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.
Worked examples
Joining two names
- Zara types print("Zara" + "Bo").
- Plus joins the two strings end to end, exactly as written.
- Neither string has a space, so the badge says ZaraBo.
Adding the space
- Zara types print("Zara" + " " + "Bo").
- The middle string is a single space inside quotes.
- The badge says Zara Bo, with the space between the names.
Counting characters
- The line is print(len("Zara Bo")).
- The characters are Z, a, r, a, a space, B and o.
- Four letters, one space and two letters: 4 + 1 + 2 = 7.
- The screen shows 7.
Two fives
- In quotes, print("5" + "5") joins two characters.
- The screen shows 55.
- Without quotes the fives are numbers, and 5 + 5 = 10, so print(5 + 5) shows 10.
A mix-up to fix
- The line print("Zara" - "Bo") does not work, because strings cannot be taken away.
- The mix-up to fix: join them with plus, as in print("Zara" + "Bo").
A taste of the worksheets
These are some of the questions on the sets. The printable sheets have more and an answer key.
- Plus joins strings exactly as written, so the space is yours to ___.
- Which line makes a badge that says Bo Zara, with a space? print("Bo" + "Zara") / print("Zara" + "Bo ") / print("Bo " + "Zara")
- Which idea about strings is not true? 📏 len tells how many characters a string has / ␣ a space is a character too / 🔡 len counts only the letters, not the spaces
- Which line counts the letters in the word robot? 🔤 print("Zara" + " " + "Bo") / 🔤 print("Zara" - "Bo") / 🔤 print(len("robot"))
- Which line shows fifty-five? 🔤 print("Zara" + "Bo") / 🔤 print("5" + "5") / 🔤 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 for
- Plus adds no space by itself. The space is yours to add, inside quotes.
- A number in quotes is text. Python does not add it, it joins it.
- Strings can be joined with plus, but not taken away with minus.
- Text and a number cannot be joined by plus, so print("Bo" + 5) has a mix-up to fix.
Try it
What does print("Bo " + "Zara") show?
Bo Zara. The space belongs to the first string.
What does print(len("robot")) show?
5. Robot has five characters.
What does print("ha" * 3) show?
hahaha. A star repeats the string, joined together.
What does print("5" + "5") show?
55. Inside quotes the fives are characters, so plus joins them.
True or false: plus adds a space between strings by itself.
False. Plus joins strings exactly as written. You add the space yourself.
For grown-ups
With 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.
Write 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.