print()
In this tutorial, we'll display text, numbers, and calculations.
print() is one of the first Python tools you will use. It displays information on the screen.
print("Hello, world!")
When this runs, Python shows:
Hello, world!
Printing Text
Text in Python is usually written inside quotes:
print("Python is fun")
print('Single quotes work too')
Both single and double quotes are fine. Choose one style and be consistent.
Printing Numbers
You can print numbers directly:
print(42)
print(3.14)
Numbers do not need quotes. If you put quotes around a number, Python treats it as text:
print(42) # number
print("42") # text
They look similar on screen, but they behave differently in calculations.
Printing Calculations
Python can calculate inside print():
print(2 + 3)
print(10 * 4)
print(20 / 5)
Output:
5
40
4.0
This is useful when testing small ideas.
Printing Variables
You can print values stored in variables:
name = "Mia"
score = 9
print(name)
print(score)
You can also print labels beside values:
print("Name:", name)
print("Score:", score)
Why print() Matters
print() helps beginners in two big ways:
- It shows output to the user
- It helps you inspect what your code is doing
If your program is not behaving as expected, printing values is often the simplest way to investigate.
Practice
Print your name, your favourite number, and the result of 8 * 7.