Python Strings
A string is text in quotes. "lida" is a string. print writes lida and leaves the quotes off. The last page added numbers: 2 + 3 was 5. Between two strings, + does a different job. It sticks the pieces together. It does not add.
Quotes turn + into joining
print("2" + "3") writes 23. The characters 2 and 3 are placed side by side. There is no sum. Drop the quotes and print(2 + 3) is the number 5 again. The quotes decide which job + does.
print("2" + "3")
A space is a string too
guest = "lida" stores text, as before. drink = "tea" stores another text. guest + drink sticks them with nothing between, so the line is lidatea. A space in quotes is a string of one character. guest + " " + drink writes lida tea.
guest = "lida"
drink = "tea"
print(guest + drink)
print(guest + " " + drink)
The first line is lidatea. The second line is lida tea. The names still hold lida and tea. The space was only in the second print.
"li" + "da" is the same stick
"li" + "da" writes lida. Order matters. "da" + "li" writes dali. Joining does not sort the pieces and does not insert a space for you.
Empty text adds no characters
"" is a string with nothing in it. "tea" + "" is still tea. It is not the word empty, and it is not a missing name. The name can hold that empty string.
Left for the next page
This page joins text. It does not change case, does not measure the text, and does not cut a piece out. The next page works on the text you already have. Numbers stay numbers. A typed line stays text until a later page turns it into a number.
Check yourself
- print("2" + "3") writes 23, not 5.
- print(2 + 3) still writes 5, because there are no quotes.
- guest + drink with no space writes lidatea.
- guest + " " + drink writes lida tea.
- "da" + "li" writes dali, not lida.
Misses
- Expecting 5 from print("2" + "3")
- Expecting lida tea from guest + drink
- Thinking + always adds, quotes or not
- Waiting for a space that you did not write
- Reading lidatea as two stored names that changed
Keep
- A string is text in quotes. + sticks strings together.
- print("2" + "3") writes 23. print(2 + 3) writes 5.
- guest + drink writes lidatea. guest + " " + drink writes lida tea.
- Order matters. "da" + "li" is dali.
- The next page works on text you already have.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top