Calculating with print
print can show the result of a calculation as well as text. Write the calculation without quotes:
print(4 + 9)
print(6 * 7)
print(1 + 3 * 5)
13
42
16Python uses + to add, - to subtract, * to multiply and / to divide. As in mathematics, multiplication and division come before addition and subtraction, so 1 + 3 * 5 is 16, not 20. Parentheses change the order: (1 + 3) * 5 is 20.
Quotes or no quotes
Quotes make all the difference. Without quotes, Python calculates. With quotes, the calculation is just text, printed exactly as it is written:
print(1 + 3 * 5)
print("1 + 3 * 5")
16
1 + 3 * 5Letting Python do the arithmetic is safer than doing it in your head and typing the answer: print(52 * 7) is easy to read and easy to check, and Python never makes a slip.