Tell text from numbers
Quick review (2 minutes)
A locker door has two printed tiles on it, a 7 and then a 2, and the label reads seventy-two.
Use addition for two integers and joining for two strings. Check for quote marks before deciding which operation this example uses.
Find the
+and the value on each side of it. In this lesson both values always have the same type.Look at the edges of each value for a pair of matching quote marks.
If both values have quotes, they are strings: write the characters of the left value, then the characters of the right value.
If neither value has quotes, they are integers: add them as you would on paper.
Write what
printshows: the result with no quote marks, on a line of its own.
A natural mistake is to assume that anything made of digits will add. You see a 7 and a 2 in both 7 + 2 and "7" + "2", so it feels natural to expect 9 from both. The quote marks change the type: inside them each digit is a character tile, and + sets the tiles side by side to make 72. Before you predict a +, look at the edges of each value, not at the digits.
1 In plain words
A locker door has two printed tiles on it, a 7 and then a 2, and the label reads seventy-two. Nobody adds them. A basket holds 7 apples, you put in 2 more, and now it holds 9. The same two digits do two different jobs: on the locker they are characters you line up, and in the basket they are amounts you count.
Python keeps the same difference. Each piece of information Python works with is a value, and Python calls the kind of a value its type. A whole number written with digits alone, such as 7, is an integer, type int. Text is a string, type str.
You write a string by putting it between quote marks, and quote marks come in pairs: the first one opens the string and the matching one closes it. Double quotes and single quotes work the same, so "7" and '7' are the same one-character string. Digits inside quotes are text, not a number. "7" is a string and 7 is an integer.
Parentheses come in pairs too. In print(7 + 2), the ( right after print opens, the last ) closes, and what sits between them is what print shows. Type both halves of every pair: each opening quote needs its closing quote, and each ( needs its ).
An expression is a small piece of Python that works out to a value, such as 7 + 2. The + sign has two jobs. Between two integers it adds them. Between two strings it glues them together, end to end. So 7 + 2 works out to 9, and "7" + "2" works out to the two-character text 72.
This lesson uses Python 3.13, and you type it in one of two places. In the editor you type lines into a file, save it and run it, as in lesson 1. In the shell you type after the >>> prompt, and Python answers on the next line; a line with no >>> in front is Python's answer, not something you type. Without Python installed, follow the printed traces with pencil and paper.
In one line: quote marks turn digits into text, text joins and numbers add. Remember to look for quote marks before you predict what a + will do. To read more, look up "Text", section 3.1.2 of the Python 3.13 tutorial, listed in this lesson's sources.
2 Picture it
For 7 + 2, seven counters plus two counters total nine. For "7" + "2", tile 7 followed by tile 2 reads 72.
3 Why
Python chooses what + does from the type of the values on each side, not from how they look on the screen. 7 and "7" show the same digit, but the first is an integer and the second is a string, because digits inside quotes are text. With two integers, + does arithmetic. With two strings, + glues the characters together, the left value first.
Python works out the expression inside the parentheses, then print turns the result into text and writes it on a line of its own. print leaves out the quote marks around a string. That is why print(7 + 2) shows 9 and print("7" + "2") shows 72, with no quote marks on either line.
4 The rule
Use addition for two integers and joining for two strings.
Check for quote marks before deciding which operation this example uses.
5 How
- Find the
+and the value on each side of it. In this lesson both values always have the same type. - Look at the edges of each value for a pair of matching quote marks.
- If both values have quotes, they are strings: write the characters of the left value, then the characters of the right value.
- If neither value has quotes, they are integers: add them as you would on paper.
- Write what
printshows: the result with no quote marks, on a line of its own.
6 Worked example
Predict both lines
print(7 + 2)
print("7" + "2")
Standard input
Empty
Standard output
9
72
On paper, count seven objects and two more. Then put a tile marked 7 next to one marked 2. The total is 9 and the two tiles read 72.
7 The trap
A natural mistake is to assume that anything made of digits will add. You see a 7 and a 2 in both 7 + 2 and "7" + "2", so it feels natural to expect 9 from both. The quote marks change the type: inside them each digit is a character tile, and + sets the tiles side by side to make 72. Before you predict a +, look at the edges of each value, not at the digits.
Quick checks
Quick check 1 of 2
A locker label must show the digit 4 followed by the digit 1, two characters that read 41. Which line displays the label, print(4 + 1) or print("4" + "1")?
Show the steps and the answer
print("4" + "1"), which displays 41.
Why: Inside quotes, 4 and 1 are one-character strings, and + lines them up in order. Without quotes, print(4 + 1) adds the integers and displays 5.
Source: Python Software Foundation, 3. An Informal Introduction to Python (Python 3.13 tutorial)
Quick check 2 of 2
One shelf holds 3 jars and another shelf holds 6. Which line displays the total number of jars, print("3" + "6") or print(3 + 6)?
Show the steps and the answer
print(3 + 6), which displays 9.
Why: A total is an amount, so the values must be integers, and + adds integers. The quoted version joins two characters and displays 36, which reads like a label, not a count.
Source: Python Software Foundation, 3. An Informal Introduction to Python (Python 3.13 tutorial)
Sources
- 3. An Informal Introduction to Python (Python 3.13 tutorial). Python Software Foundation. PSF License Version 2 (documentation examples also Zero-Clause BSD). Read 25 Nov 2026.
- Built-in Functions: print (Python 3.13). Python Software Foundation. PSF License Version 2 (documentation examples also Zero-Clause BSD). Read 25 Nov 2026.