print()
Sending Output to stdout
print()
MattersThe 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.
print(*objects, sep=' ', end='\\n', file=sys.stdout, flush=False)
*objects
– one or more items to display.sep
– text inserted between items (default space).end
– text appended after the final item (default newline).flush
– force flushing the output buffer when True
.name = "John"
age = 55
print(f"Hello, {name}! You are {age} years old.")
numbers = [1, 2, 3, 4, 5]
print(*numbers, sep=" | ", end=" <-- list complete\n")
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.