Output
When you put something inside print(), Python works out the item first and then shows it as text. A number is shown as its value, an expression is calculated before anything appears, and characters in quotation marks are shown exactly as they were typed.
A number can go straight into the brackets with no quotation marks, so print(27) shows 27. An expression without quotation marks is evaluated first: Python works it out and prints only the result. If a bus has 52 seats and 19 are taken, print(52 - 19) prints 33, never the sum itself. The same happens with multiplication, where print(8 * 7) prints 56.
Quotation marks turn the characters into a string, so nothing is calculated: print('52 - 19') prints 52 - 19. The brackets hold the item that print sends to the screen; the quotation marks mean that item is just characters.
A function call placed inside the brackets is run first, and the value it returns is what gets printed. len('basketball') returns 10, so print(len('basketball')) prints 10. Text handed to a function must be in quotation marks; without them Python reads the word as a variable name and the program stops with an error.
# A number, an expression, quoted text and a function call
print(27)
print(52 - 19)
print('52 - 19')
print(len('basketball'))Output:
27
33
52 - 19
10 OCR GCSE Computer Science · Output