Numbers and strings
Variables can hold numbers as well as strings. A whole number, such as 7, -40 or 1000000, is called an integer. You write it without quotes:
year = 2026
print(year)
print(year + 1)
2026
2027"25" is not 25
With quotes, "25" is a string: two characters that happen to be digits. A locker number and a door code may look alike when printed, but Python treats them differently:
lockers = 25
door_code = "25"
print(lockers)
print(door_code)
print(lockers + lockers)
print(door_code + door_code)
25
25
50
2525For numbers, + adds. For strings, it joins. What an operator does depends on the type of the values it works on: whether they are integers, strings or something else. Python's short name for the integer type is int, and for the string type it's str.
A look in the interpreter
Python also has an interactive interpreter: you type one line after its >>> prompt, and Python runs it and shows the value right away. It shows a string with its quotes, so you can tell the string '34' from the number 34:
>>> 3 + 4
7
>>> "3" + "4"
'34'Not every operation works for every type
Taking a number away from a string makes no sense, and Python says so:
width = "12"
print(width - 2)
Traceback (most recent call last):
File "main.py", line 2, in <module>
print(width - 2)
~~~~~~^~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'A TypeError means that an operation got values of a type it can't work with. The last line says that - doesn't work on a str and an int (the values an operator works on are its operands). The ~ and ^ marks show the calculation that failed. The fix here is to drop the quotes, so that width holds a number.
Keep in mind that what input gives you is always a string, even when the user types digits. The next module shows how to turn it into a number.