LambdaLabTM
Computer Science · Class 11 · Displaying Output
OutputTypes⏱️ 9 min read

Numbers, Booleans & Expressions

Strings are not the only thing print() accepts. Give it a number and it prints the number. Give it a sum and something interesting happens: Python works out the answer first, and prints only the answer.

1Numbers need no quotes

Numbers go straight inside the parentheses, with no quotes. If you put quotes around a number, it is not a number any more. It becomes text that looks like a number.

Python prompt — interactive mode
>>> print(42) # an integer — a whole number
42
>>> print(3.14) # a float — it has a decimal point
3.14
>>> print('42') # a STRING — it only looks like a number
42
int
Integer

A whole number, with no decimal point: 7, 0, -15, 1000000.

float
Float

A number with a decimal point: 3.14, -0.5, 2.0. Even 2.0 is a float, because it has the point.

Note
Python has a third number type called complex (numbers like 3 + 4j). It is not in your syllabus. It is mentioned only so that you are not surprised if you ever see it.

2Booleans: only two values

A boolean has only two possible values: True and False. Python uses them to answer yes-or-no questions. Later they will control the decisions your programs make. Two rules about them are strict:

Capital first letter
True · False

Lowercase true is not a boolean. Python looks for something called true, does not find it, and gives a NameError.

Never in quotes
'True' is a string, not a boolean

It prints the same way, which is why it is easy to get wrong. But with quotes it is just a word, not a yes/no value.

3Expressions are worked out first

If you give print() a sum, it does not print the sum. Python works out the answer first, and gives only that answer to print(). The maths happens before anything is printed.

Python prompt — interactive mode
>>> print(2 + 3)
5
>>> print(10 - 4)
6
>>> print(100 + 250 - 50)
300

Python never showed 2 + 3. It showed 5. The sum was worked out first, and only the answer reached print(). Notice also that there are no quotes around the sum — quotes would have turned it into text, and then Python would have shown 2 + 3 just as you typed it.

Key Takeaway
A sum inside print() is worked out first. Only the answer is printed.

Try a few of your own at the prompt:

Python prompt — interactive mode
# Type a sum inside print() and press Enter.
>>>
try
Tip
Try the last one. print('2 + 3') has quotes, so it is text. Python shows it exactly as written: 2 + 3. No maths happens at all.

4Try them yourself

Every value below can go inside print() — except one, which is there to break. Click through them and see what comes back.

Put something inside print( … ) and click it
the line you write
print('Hello, world!')
what appears on screen
Hello, world!
str

A string: text inside quotes. The quotes only wrap it. They are not printed.

5Mixing types in one print()

Commas do not mind at all. When you separate arguments with commas, you can mix strings, numbers and booleans freely. Each one is printed on its own.

Python prompt — interactive mode
>>> print('Student:', 'Ramesh', '| Marks:', 87, '| Passed:', True)
Student: Ramesh | Marks: 87 | Passed: True

One line, and it holds a string, a number and a boolean together. The commas keep them apart. Try it, and put your own name and marks in:

Python prompt — interactive mode
# Mix strings, numbers and booleans — commas keep them apart.
>>>
try
Key Takeaway
A comma keeps things separate and prints them side by side with a space between them. It does not care what types they are.

6Recap

Key Takeaway
print() accepts strings (in quotes), integers and floats (no quotes), booleans (True / False, capital letter, no quotes) and expressions — sums, which Python works out first, printing only the answer.
Quick Check

What does print(2 + 3) show?

Quick Check

What does print('2 + 3') show — with the quotes?

Quick Check

Which one is a real boolean?