Python print()
In this page:
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
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
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
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
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
print("Line1\nLine2")
print("Name:\tAlex")
Chapter Quiz — Complete all 16 topics to unlock
0/16 topics done
Complete these topics first:
- Python print()
- Python input()
- Python Format Strings
- Python f-strings
- Python String Formatting
- Python Arithmetic Operators
- Python Relational Operators
- Python Logical Operators
- Python Bitwise Operators
- Python Assignment Operators
- Python Increment & Decrement
- Python Ternary Operator
- Python Operator Precedence
- Python Identity Operators
- Python Membership Operators
- Python Operators