Python print()

Sending Output to stdout

Why print() Matters

The built‑in print() function is the quickest way to display information in Python. It’s invaluable for debugging, logging progress, and presenting results to users.

Syntax Overview

Example 1: Basic Usage with f‑Strings

name = "John"
age = 55
print(f"Hello, {name}! You are {age} years old.")

Example 2: Custom Separators and Endings

numbers = [1, 2, 3, 4, 5]
print(*numbers, sep=" | ", end=" <-- list complete\n")

Example 3: Printing to a File

with open("log.txt", "a") as log:
    print("Computation finished successfully.", file=log, flush=True)
print("Log written!")

These snippets show how versatile print() can be—from simple messages to structured output and file logging.