Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 10+ · Coding · Python
Strings
print("Zara" + "Bo")• two strings, no space• the badge says ZaraBoprint("Zara" + " " + "Bo")• a space in quotes sits between• the badge says Zara Bo
Plus joins strings exactly as written.
The big ideaA string is text in quotes. Plus joins strings end to end.

How it works

Text in quotes is called a string. A string is a row of characters, like beads on a string.

Letters, spaces and digits all count as characters.

Plus joins strings end to end, exactly as written. It never adds a space for you.

Len counts the characters in a string, spaces too. A 5 inside quotes is only a character, not a number.

1print(len("robot"))2print(len("Zara Bo"))
Len counts every character, spaces too.
Letters• Z, a, r, a: four• B, o: twoAnd the space• one space• 4 + 1 + 2 = 7 characters
Counting the characters in Zara Bo.

Example 1: Joining two names

  1. Zara types print("Zara" + "Bo").
  2. Plus joins the two strings end to end, exactly as written.
  3. Neither string has a space, so the badge says ZaraBo.

Example 2: Adding the space

  1. Zara types print("Zara" + " " + "Bo").
  2. The middle string is a single space inside quotes.
  3. The badge says Zara Bo, with the space between the names.

Example 3: Counting characters

  1. The line is print(len("Zara Bo")).
  2. The characters are Z, a, r, a, a space, B and o.
  3. Four letters, one space and two letters: 4 + 1 + 2 = 7.
  4. The screen shows 7.

Example 4: Two fives

  1. In quotes, print("5" + "5") joins two characters.
  2. The screen shows 55.
  3. Without quotes the fives are numbers, and 5 + 5 = 10, so print(5 + 5) shows 10.

Example 5: A mix-up to fix

  1. The line print("Zara" - "Bo") does not work, because strings cannot be taken away.
  2. The mix-up to fix: join them with plus, as in print("Zara" + "Bo").

Words to know

string
Text in quotes, a row of characters.
character
One letter, digit or space inside a string.
len
A tool that counts the characters in a string.
join
Plus puts two strings end to end.

Watch out

Try it

  1. What does print("Bo " + "Zara") show?
  2. What does print(len("robot")) show?
  3. What does print("ha" * 3) show?
  4. What does print("5" + "5") show?
  5. True or false: plus adds a space between strings by itself.
Answers: 1. Bo Zara · 2. 5 · 3. hahaha · 4. 55 · 5. False
Try at homeWith a grown-up, write a short sentence and cut it into word strips. Join two strips edge to edge and read the result: that is plus. Decide where the space strip goes, then count the characters in one word, just like len does.
For grown-upsWrite a short sentence on paper and cut it into word strips. Join two strips edge to edge and read the result: that is plus. Decide where the space strip goes, then count the characters in one word.
Open these notes on screenScan the code, or go to tutorpip.com.