print() is Python’s most iconic built-in function — it outputs text, values, or formatted strings to the console (stdout), files, or other streams, making it essential for debugging, logging, user feedback, progress reporting, and interactive scripts. In 2026, print() remains the go-to tool in data science (quick inspection of pandas/Polars/Dask results), software engineering (CLI apps, logging), and teaching/learning — now enhanced with f-strings, rich formatting (rich), positional arguments, sep/end/file/flush control, and seamless integration with tqdm progress bars, Jupyter notebooks, and modern logging systems.
Here’s a complete, practical guide to using print() in Python: basic output, formatting techniques, real-world patterns (earthquake data display, progress logging, file output), and modern best practices with f-strings, rich styling, performance, redirection, and integration with pandas/Polars/Dask/tqdm/logging.
Basic print() — output strings, variables, expressions, multiple arguments.
print("Hello, World!") # Hello, World!
print(42) # 42
print(3.14, True, [1, 2, 3]) # 3.14 True [1, 2, 3]
# Multiple arguments with separator
print("Mag:", 7.2, "in", "Japan") # Mag: 7.2 in Japan
print("Mag:", 7.2, "in", "Japan", sep=" - ") # Mag: - 7.2 - in - Japan
# Custom end (no newline)
print("Loading", end="...") # Loading... (no newline)
print("done!") # done! (continues on same line)
Advanced formatting — f-strings (preferred), .format(), old-style %.
mag = 7.2
place = "Japan"
depth = 25.0
# f-strings (fastest, most readable)
print(f"Mag {mag:.1f} at {place} (depth {depth:.1f} km)")
# Mag 7.2 at Japan (depth 25.0 km)
# .format() (legacy, still common)
print("Mag {:.1f} at {} (depth {:.1f} km)".format(mag, place, depth))
# Old-style % formatting (avoid in new code)
print("Mag %.1f at %s (depth %.1f km)" % (mag, place, depth))
Real-world pattern: formatted earthquake report & progress logging.
import pandas as pd
from tqdm import tqdm
df = pd.read_csv('earthquakes.csv')
# Pretty table of top strong events
strong = df[df['mag'] >= 7.0].sort_values('mag', ascending=False).head(5)
print("\nTop 5 Strongest Earthquakes:")
print("-" * 60)
for i, row in strong.iterrows():
print(f"{i+1:2d}. Mag {row['mag']:.1f} | {row['place']:<30} | {row['time']}")
print("-" * 60)
# Progress bar with print
for i in tqdm(range(100), desc="Processing chunks"):
# simulate work
if i % 20 == 0:
print(f" Chunk {i:3d}: found {i*10} strong events", flush=True)
Best practices for print() in Python & data workflows. Prefer f-strings — f"Mag {mag:.1f}" — fastest, most readable, supports expressions. Modern tip: use rich — from rich.console import Console; console = Console(); console.print(f"[bold red]Mag {mag:.1f}[/bold red]") — styled output. Use sep/end/file/flush — control spacing, newlines, redirection, immediate flush. Add type hints — def log_event(mag: float, place: str) -> None: print(f"Mag {mag:.1f} at {place}"). Use print(..., file=sys.stderr) — for errors/warnings. Use with open('log.txt', 'a') as f: print(..., file=f) — file logging. Use tqdm — progress bars with print() inside loop. Use logging module — for production logging instead of print(). Use pprint.pprint() — pretty-print complex objects. Use print(f"{var=}") — debug (Python 3.8+): print(f"{mag=:.1f}") ? "mag=7.2". Use print(*objects, sep=' ') — unpack lists: print(*row). Use print() with flush=True — real-time output in long loops. Use print(repr(obj)) — debug with quotes/escapes. Use print(json.dumps(data, indent=2)) — pretty JSON. Use print(df.to_string()) — full DataFrame without truncation. Use print(df.head().to_markdown()) — markdown table output. Use rich.table — beautiful tables in terminal. Use textual — full TUI with print-like output. Use rich.progress — advanced progress bars with print integration.
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) outputs to console/file with flexible formatting — f-strings, sep/end/file/flush control, and rich styling. In 2026, prefer f-strings for dynamic text, rich for styled output, logging for production, and integrate with tqdm/pandas/Polars/Dask for progress & data display. Master print(), and you’ll create clear, informative, interactive console experiences in any Python project.
Next time you need to show something — use print(). It’s Python’s cleanest way to say: “Display this — formatted, flushed, and ready for the user.”