Built-in Functions
print()
Print objects to the text stream file, separated by sep and followed by end.
print(*objects, sep=' ', end='\n', file=None, flush=False)
print() writes the string representations of one or more objects to a text stream (defaults to standard output sys.stdout), separated by sep and followed by end.
All non-keyword arguments are converted to strings like str() does and written to the stream. You can customize separators, change or omit trailing newlines, redirect output to files, or force immediate buffer flushing.
Parameters
| Name | Description |
|---|---|
| *objects | One or more values or objects to display. Multiple items are separated by sep. |
| sep | Optional string inserted between values when multiple objects are passed. Defaults to a single space ' '. |
| end | Optional string appended after the last value. Defaults to a newline '\n'. Use '' to keep the cursor on the same line, or '\r' for carriage return. |
| file | Optional object with a write(string) method. Defaults to sys.stdout (the console). |
| flush | Optional boolean. If True, the output stream is forcibly flushed immediately without waiting for buffer fills. Defaults to False. |
Returns
None — print() outputs text to the stream but returns no value.
Try it
Run it and change it
items = ["Python", "3.14", "Ready"] print(*items, sep=" | ", end="!\n")
Another example
for count in [1, 2, 3]:
print(count, end="... ")
print("Go!")
Worth knowing
- Custom separators (sep): Pass any string such as
sep=','orsep=' -> 'to control how multiple values are joined. - Controlling line endings (end): Set
end=''to prevent automatic newlines so subsequent prints continue on the same line. - Carriage return (\r): Using
end='\r'returns the cursor to the beginning of the line, enabling in-place console animations, progress counters, and status updates. - Immediate output (flush=True): Standard output is buffered for efficiency. Passing
flush=Trueforces characters to render on screen immediately, essential for real-time prompts and countdowns. - Writing to files (file): You can redirect output to a file object by passing
file=open('output.txt', 'w').