Python Reference Library →

Python print() Function – Print Output to the Console

Let’s look at print() function – print output to the console

  1. Notice

    print() converts its arguments to text and writes them to output. sep separates arguments; end controls what follows them.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
word = 'tea'
print(word, "ready", sep=" | ", end="!\n")
Live state

Top-level scope

word→Object 1
Object 1 · str'tea'
This step

print() converts its arguments to text and writes them to output. sep separates arguments; end controls what follows them.

Picture print() function – print output to the console

print() converts its arguments to text and writes them to output. sep separates arguments; end controls what follows them.

Image brief

Alt text
A diagram for Python print() Function – Print Output to the Console. Instructions: word = 'tea' print(word, "ready", sep=" | ", end="!\n"). Displayed result: tea | ready!. The final example bindings are word --> object 1 (str). object 1: 'tea'
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python print() Function – Print Output to the Console". Teaching focus: print() converts its arguments to text and writes them to output. sep separates arguments; end controls what follows them. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS word = 'tea' print(word, "ready", sep=" | ", end="!\n") | v DISPLAYED RESULT tea | ready! FINAL BINDINGS word --> object 1 (str) object 1: 'tea' Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python print() Function – Print Output to the Console. Instructions: word = 'tea' print(word, "ready", sep=" | ", end="!\n"). Displayed result: tea | ready!. The final example bindings are word --> object 1 (str). object 1: 'tea'

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
word = 'tea'
print(word, "ready", sep=" | ", end="!\n")
Live state

Top-level scope

word→Object 1
Object 1 · str'tea'
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
tea | ready!

What do you expect this program to print?

What does this example display?

word = 'tea'
print(word, "ready", sep=" | ", end="!\n")
What does this example display?
Choose one answer. You can try again.

Answer and explanation

tea | ready!

Follow the printed values in order. The output is: tea | ready!

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

print() converts its arguments to text and writes them to output. sep separates arguments; end controls what follows them.

print() converts its arguments to text and writes them to output. sep separates arguments; end controls what follows them.

More examples and reference

Python print() Function

The print() function is one of the most commonly used built-in functions in Python. It displays the given message or values on the screen (standard output).

Syntax

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

Parameters:

  • *objects – One or more expressions to be printed.
  • sep – String inserted between values. Default is a space.
  • end – String added after the last value. Default is newline '\n'.
  • file – Where to print. Default is the console (standard output).
  • flush – Whether to forcibly flush the stream. Default is False.

Basic Example

print("Hello, World!")
Hello, World!

Example: Printing Multiple Values

print("Name:", "Alice", "Age:", 25)
Name: Alice Age: 25

Example: Using sep and end

print("apple", "banana", "cherry", sep=", ", end=".")
apple, banana, cherry.

Use Case: Printing in Loops

for i in range(3):
    print("Line", i)
Line 0
Line 1
Line 2

Print with Formatting

name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old.")
My name is Alice and I am 25 years old.

Print to a File

with open("output.txt", "w") as f:
    print("Writing to file", file=f)

Common Mistakes

  • Using print without parentheses in Python 3 (works in Python 2 only)
  • Expecting print() to return a value – it returns None

Interview Tip

print() is often used for debugging. Knowing how to format outputs and print in loops can help during problem solving rounds.

Summary

  • print() sends output to the screen.
  • You can customize output using sep, end, and file.
  • Supports f-strings and multiple arguments.

Practice Problem

Write a Python program that asks for your name and prints: Hello, <your name>!

name = input("Enter your name: ")
print("Hello,", name + "!")

What to remember

Connect what you noticed in the example with the idea below.

Remember

print() converts its arguments to text and writes them to output. sep separates arguments; end controls what follows them.

Watch out for this idea

sep controls the text that follows the last argument.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →