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.
Len counts every character, spaces too.Counting the characters in Zara Bo.
Example 1: 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.
Example 2: 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.
Example 3: 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.
Example 4: 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.
Example 5: 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").
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
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?
What does print(len("robot")) show?
What does print("ha" * 3) show?
What does print("5" + "5") show?
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.