Python Output (print)
To show something on the screen, Python programs use the built-in function print. It writes its values to the terminal and then moves to a new line. You will use print in almost every program, so it is worth knowing its options.
Printing several values
print can take several values separated by commas. It prints them on one line with a space between them. The values can be text, numbers, or anything else:
print("Hello")
print("I am", 21, "years old")
print(3.5, True, "done")
print()
print("The line above is empty.")Hello I am 21 years old 3.5 True done The line above is empty.
print() with nothing inside prints an empty line. Numbers are printed as they are, without quotes.
The sep and end options
Two optional arguments change how print joins and ends its output. sep is the text put between the values (a space by default), and end is the text put after the last value (a new line by default):
print("2026", "10", "21", sep="-")
print("Loading", end="")
print("...", end=" ")
print("done")
print("a", "b", "c", sep="")2026-10-21 Loading... done abc
With end="" the next print continues on the same line. This is useful for building a line in several steps.
Escape sequences
Some characters cannot be typed directly inside a string. A backslash starts an escape sequence: \n is a new line, \t is a tab, \" is a double quote inside a double-quoted string, and \\ is a backslash itself:
print("Line one\nLine two")
print("Name:\tAsha")
print("She said \"hello\"")
print("C:\\Users\\asha")Line one Line two Name: Asha She said "hello" C:\Users\asha
You can also use single quotes around a string that contains double quotes, 'She said "hello"', and the other way round. Both kinds of quotes make the same kind of string.
Practice exercises
- Print your name, your age and your city on one line using one
printwith three values. - Print the date
21/10/2026usingsep. - Print the numbers 1 to 5 on one line, separated by spaces, using five
printcalls withend. - Print a small table with two columns separated by
\t.