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

Python print()

print() is how your program talks to you by showing messages on the screen. It is like a speaker that reads out whatever you hand it.
Syntax
python
print(value1, value2, sep=" ", end="\n")

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="")  # end="" suppresses the default newline
print("...", end="")
print("done")  # this print still ends with the default newline

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")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Forgetting parentheses or quotes, as in print Hello, which raises a SyntaxError or NameError.
  2. Concatenating a string and a number with +, as in print("Age: " + 25), which raises TypeError; use a comma or an f-string.
  3. Being surprised that each print() ends with a newline, and not using end="" to keep output on one line.

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.