Member-only story
Everything You Need to Know About Python’s print() Function
2 min readJan 2, 2025
The print
function in Python is one of the most commonly used built-in functions. It outputs text or other data to the console or a specified file-like object. Here's a detailed overview:
Syntax of print() Function
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Parameters
*objects
:
- Accepts one or more objects to print. These objects are converted to strings and displayed.
print("Hello", "World", 123)
# Output: Hello World 123
sep
(optional):
- Specifies the separator between objects. Default is a space (
' '
).
print("Hello", "World", sep="-")
# Output: Hello-World
end
(optional):
- Specifies the string appended at the end of the output. The default is a newline (
'\n'
).
print("Hello", end=" ")
print("World")
# Output: Hello World
file
(optional):
- Specifies the file-like object to write the output. Default…