Printing & Output
Printing Numbers
To print a number, just put it inside print():
print(5)
Output:
5
Decimal numbers work the same way:
print(3.78)
3.78
You can also use multiple print() statements. Each one prints on its own line:
print(5)
print(3.78)
5
3.78
Calculations Inside print()
You can do math directly inside print() and Python will show you the result:
print(5 + 1) # 6
print(6.1 * 2) # 12.2
print(4 + 3 + 4) # 11
6
12.2
11
Printing Text
To print text, wrap it in quotation marks. Without them, Python thinks it's a variable name and throws an error:
print(hello) # ❌ Error — Python looks for a variable called hello
print("hello") # ✅ Correct
hello
You can use either double quotes "..." or single quotes '...' — both work exactly the same:
print("hello")
print('I am learning Python')
hello
I am learning Python
Notice that the quotes themselves don't appear in the output — only the text inside them does.
You have to use the same type of quote on both sides. Mixing them causes an error:
print('I am learning Python") # ❌ Error — mismatched quotes
Printing Quotes Inside Text
What if you want the quote character itself to appear in the output? Use the other type of quote as the wrapper:
print('"hi"') # wrap in single quotes to print double quotes
print("it's") # wrap in double quotes to print a single quote
"hi"
it's
Numbers vs Text — What's the Difference?
Both of these print 5 on screen:
print(5) # number
print("5") # text
So why does it matter? Because Python treats them differently when you do something with them:
print(5 + 5) # 10 — Python adds the numbers
print("5 + 5") # 5 + 5 — Python prints it exactly as written
10
5 + 5
When something is wrapped in quotes, Python treats it as text and prints it as-is. Without quotes, Python treats it as a number and can use it in calculations.
Have anything to say about this lesson?
Your feedback helps improve these tutorials. If something was confusing or missing, let us know.