PY-101 ยท Getting started with Python
print() and your first program
โฑ 9 min ๐ Real Python 3 ๐ฌ Animated โ Completed
โก The 30-second answer
print() is the built-in Python function that shows values on the screen. You can pass it several values separated by commas, and it puts a space between them and a new line at the end. The sep and end arguments change those two defaults.
- Print text and numbers
- Print several values at once
- Control spacing with sep and end
- Use \n for a new line
Try it
Watch it come alive, run it yourself, then prove it. Real Python, right on this page.
Watch Python run the example. Every variable is a jar; watch the values change and the output appear.
print("Hello, world!")print("Score:", 42)print("a", "b", "c", sep="-")print("No new line", end=" ")print("...continued")print("Line 1\nLine 2")
Change anything and press Run (or Ctrl+Enter). Then open Watch it and press Watch my code.
Input one line per input() call
Press Run to see the output. Python runs in your browser. Expected output
Hello, world!
Score: 42
a-b-c
No new line ...continued
Line 1
Line 2 ๐ฏ Print today's date as 2026-12-01 by passing "2026", "12" and "01" as three separate values to one print() call. Use sep.
Input one line per input() call
Press Run to see the output. Python runs in your browser. Need a hint?
Add sep="-" as the last argument.
- The problemYour program runs, finishes, and shows nothing. Did it work? Without print() you cannot tell. Even senior developers still reach for print first when something looks wrong.
- The Python idea
print(value1, value2, ..., sep=" ", end="\n")print() is the built-in Python function that shows values on the screen. - In real lifeLog files are mostly print-style lines: a time, a level and a message joined by a separator. Changing sep is how you turn the same values into a CSV row.
Start with a question
Your program runs, finishes, and shows nothing. Did it work? Without print() you cannot tell. Even senior developers still reach for print first when something looks wrong.
print() is how you see what your program is doing. Professional developers still use it every day to check values while they debug.
Explain it like I'm 10
print() is your program's voice. Whatever you put inside the brackets, it says out loud on the screen.
The technical explanation
Text must be inside quotes. Single quotes and double quotes work the same: print('hi') and print("hi") both print hi.
When you pass several values, print("Score:", 42) prints them with one space between. Numbers do not need quotes.
sep sets what goes between values and end sets what goes after the last one. By default they are a space and a new line.
Inside a string, \n starts a new line and \t inserts a tab. These are called escape sequences.
Syntax
print(value1, value2, ..., sep=" ", end="\n") Real-world scenario
Log files are mostly print-style lines: a time, a level and a message joined by a separator. Changing sep is how you turn the same values into a CSV row.
Test yourself
5 questions. Get 4 right and this lesson is marked complete.
Pass the quiz to complete this lesson.
๐ Every lesson counts toward your certificate Next: Comments โQuestions people ask
What is the difference between single and double quotes in Python?
There is none for normal strings. Pick one style and stay with it. Use the other kind when your text contains a quote, for example "It's ready".
Why does print need brackets in Python 3?
In Python 3, print became a function, and functions are called with parentheses. The bracket-free form print "hi" only worked in Python 2, which reached end of life in 2020.
Interview questions
How this topic comes up in Python interviews. Answer out loud first, then open the model answer.
beginner What is the difference between single and double quotes in Python?
There is none for normal strings. Pick one style and stay with it. Use the other kind when your text contains a quote, for example "It's ready".
beginner Why does print need brackets in Python 3?
In Python 3, print became a function, and functions are called with parentheses. The bracket-free form print "hi" only worked in Python 2, which reached end of life in 2020.
intermediate What does print("a", "b") show?
a b. Values separated by commas are printed with a single space between them, because sep defaults to " ".
intermediate What does print("x", "y", sep="") show?
xy. sep="" puts nothing between the values.
Quick revision
Remember
- Print text and numbers
- Print several values at once
- Control spacing with sep and end
- Use \n for a new line
- Commas add a space for you:
print("Total:", 5)showsTotal: 5. Do not put your own space inside the quotes as well, or you get two.
Syntax
print(value1, value2, ..., sep=" ", end="\n") Official documentation
- Built-in functions: print() (docs.python.org)