BBampaa

Lessons › Python

Python lesson

Joining text with +

+ joins the pieces exactly as they are, so we add the space in the middle ourselves: Ada Obi.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Text in Python is called a string. + joins strings end to end:

first = "Ada"
last = "Obi"
full = first + " " + last
print(full)

Output:

Ada Obi

Key points

"Ada" + "Obi"+ joins text end to end: AdaObi, with no space.
" "Add the space yourself, as its own piece of text in quotes.
"35" + "5"Numbers in quotes are text: this gives 355, not 40.

Put together: full = first + " " + last.

Practice

Try each one in your head first, then open the answer.

1. Build a line that joins first and last, with a space between, into full.
full = first + " " + last
2. Build a line that shows the word Order: followed by the id in oid.
print("Order: " + oid)
3. Join "Phone" and "case" with a space into a variable called product, then print it.
product = "Phone" + " " + "case"
print(product)
4. Print the text Store: followed by the store name, so it reads Store: Lagos
store = "Lagos"
print("Store: " + store)
5. Print the city and country joined with a comma and a space, so it reads Lagos, Nigeria
city = "Lagos"
country = "Nigeria"
print(city + ", " + country)

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed