TExcelTAD
Home › Python › Python Output

Python Output

Showing information on the screen is the first thing most programs do. In Python you use the built-in print() function. It looks simple, but it has a few handy options worth knowing.

Printing values

print() accepts any value — text, numbers, lists, even the result of a calculation:

python · try it yourself
print("Good morning")
print(42)
print(3.75)
print(10 * 4)
print([1, 2, 3])
Good morning
42
3.75
40
[1, 2, 3]

Calling print() with nothing inside prints an empty line.

Several values at once

Separate values with commas. print() puts a single space between them automatically and converts each one to text for you:

python · try it yourself
name = "Mai"
age = 27
print("Name:", name, "Age:", age)
Name: Mai Age: 27

Changing the separator with sep

The sep keyword argument controls what goes between the values:

python · try it yourself
print("2025", "03", "14", sep="-")
print("a", "b", "c", sep="")
print("red", "green", "blue", sep=" | ")
2025-03-14
abc
red | green | blue

Changing the line ending with end

By default each print() finishes with a newline character \n. Change it with end to keep printing on the same line:

python · try it yourself
print("Loading", end="")
print(".", end="")
print(".", end="")
print(". done!")

for i in range(1, 6):
    print(i, end=" ")
print()
Loading... done!
1 2 3 4 5 

The final empty print() simply moves to a new line after the loop.

Special characters

Inside a string, a backslash starts an escape sequence:

Escape Meaning
\n New line
\t Tab
\\ A literal backslash
\" / \' A quote inside a string that uses the same quote
python · try it yourself
print("Line one\nLine two")
print("Name\tScore")
print("She said \"hi\"")
print('It\'s fine')
print("C:\\Users\\demo")
Line one
Line two
Name	Score
She said "hi"
It's fine
C:\Users\demo

Combining text and numbers

You cannot add a string and a number with +:

python
print("Total: " + 5)   # TypeError: can only concatenate str (not "int") to str

Use commas, convert with str(), or — the modern favourite — use an f-string (covered in detail in String Formatting):

python · try it yourself
items = 3
price = 4.5
print("Items:", items)
print("Items: " + str(items))
print(f"{items} items cost {items * price} dollars")
Items: 3
Items: 3
3 items cost 13.5 dollars

Tip: f-strings are usually the clearest way to build output that mixes text and values.

Test yourself

What does print("a", "b", sep="-") output?

  1. a b
  2. ab
  3. a-b
  4. a - b

Which argument stops print() from moving to a new line?

  1. sep=""
  2. end=""
  3. newline=False
  4. flush=True

What does the escape sequence \t produce?

  1. A tab
  2. The letter t
  3. A new line
  4. A backslash