print() (Python)
print() is Python's built-in function for displaying output to the console (terminal). It shows whatever you pass it as text and adds a new line at the end.
Python
Use print() to show a result while your program runs: a greeting, a calculated total, or a value you are checking. Text in quotes is literal text; a name without quotes is looked up as a variable. In the first example, printing "name" shows the word name, while printing name shows the value stored under that name.
Pass several values with commas when you want to display text and numbers together. print() converts each value to text and puts a space between them by default. You do not need to convert the number to a string yourself. A comma here separates function arguments; it does not print a comma on the screen.
Use sep to change the text between values in one call. It does not add anything before the first value or after the last. The named argument sep="-" makes a date-like label with hyphens. If you pass only one value, there is no gap for sep to change.
Use end to change what comes after the final value. Its default is a newline, which moves the next print to a new line. The example with end=" | " deliberately keeps two calls on the same line. An empty print() writes just its ending: with the defaults that is a newline, which finishes the current line. When the previous line was already finished, as in the example, the result is a blank line.
Displaying a value does not save it for later. print() returns None, so assigning its result to a variable does not capture the text it displayed. In the last example, save the calculated total first, then print it when you want to show it. The separate result variable demonstrates what assigning the return value of print() actually stores.
Before reading each output, predict where each line ends and whether quotes will be displayed. Then try it yourself: copy an example into the Python editor in the linked lesson, change sep="-" to sep=" / " and end=" | " to end="", and run it. Only formatting should change: the values you passed to print remain the same. If you need a reusable formatted string, see the linked f-string reference.
Syntax
print(*objects, sep=' ', end='\n')Examples
Python — Quoted text and a variable name are different.
name = "Sam"
print("name")
print(name)Output:
name
SamPython — Commas separate arguments; the default separator is a space.
name = "Sam"
lessons = 3
print(name, "completed", lessons, "lessons")Output:
Sam completed 3 lessonsPython — sep goes between values, not after the last one.
print(2026, 11, 4, sep="-")
print("done", sep="-")Output:
2026-11-4
donePython — end controls where the next print starts.
print("Saved", end=" | ")
print("Ready")
print()
print("Next task")Output:
Saved | Ready
Next taskPython — Keep the calculated value, not the return value of print().
total = 4 + 3
result = print(total)
print("Stored total:", total)
print("print returned:", result)Output:
7
Stored total: 7
print returned: None