← Back to Python Course | Chapter 2: Input, Output & Operators | Lesson 1 of 16

Python print()

Basic print() Usage

print() writes its argument to standard output followed by a newline — pass it a string, a number, or any object, and Python converts it to text automatically before displaying it. It's the single most-used tool for inspecting values while a program runs.

Example: Basic print() Usage

python
print("Hello")
print(42)

Printing Multiple Items

Passing several comma-separated values to print() displays them all on one line, with a single space inserted between each item by default — handy for combining a label and a value without manually building a string first, like print("Score:", score).

Example: Printing Multiple Items

python
score = 95
print("Score:", score)

Custom Line Endings

The end keyword argument controls what print() appends after its output — it defaults to "\n" (a newline), but setting end="" or end=", " lets you print several values on the same line or build up custom output formatting.

Example: Custom Line Endings

python
print("Loading", end="")
print("...", end="")
print("done")

Printing Expressions and Math

Because print() evaluates its argument before displaying it, writing print(3 * 4) computes 12 first and prints that result — useful for quick arithmetic checks without needing to store the calculation in a variable first.

Example: Printing Expressions and Math

python
print(3 * 4)

Special Escape Characters

Escape sequences let you embed control characters inside an ordinary string: \n inserts a line break and \t inserts a tab, both commonly used to format multi-line or column-aligned console output cleanly.

Example: Special Escape Characters

python
print("Line1\nLine2")
print("Name:\tAlex")

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.