print() FunctionPython's built-in function for displaying output โ what it can print, and how sep and end control the formatting.
print() is Python's built-in function for displaying output to the console (or another stream). This note covers what kinds of values it can print, and its keyword arguments sep and end, which control how multiple values are separated and what's printed after the last value.
print() can take any data type as an argument โ strings, integers, floats, booleans, or multiple values separated by commas.sep controls the separator placed between multiple values (default is a single space ' ').end controls what is appended after the last value (default is a newline '\n'), which affects whether consecutive print() calls appear on the same line or different lines.print() also supports file and flush keyword arguments (less commonly used, covered below).print() works with any single value, regardless of type:
print("Hello World") # -> Hello World (string)
print(6) # -> 6 (integer)
print(5.6) # -> 5.6 (float)
print(False) # -> False (boolean)
Note: Python automatically converts the value to its string representation for display โ you don't need to manually convert types before printing.
You can pass multiple comma-separated values to print(), and it will print them all on one line, separated by a space by default:
print("India", "Pakistan", "Nepal", "Srilanka")
# -> India Pakistan Nepal Srilanka
Multiple values don't need to be the same type:
print("India", 5, True)
# -> India 5 True
sep Parameter โ Custom SeparatorsBy default, print() joins multiple values with a space. The sep parameter lets you change this separator to any custom string.
print("India", "Pakistan", "Nepal", "Srilanka", sep='/')
# -> India/Pakistan/Nepal/Srilanka
print("India", "Pakistan", "Nepal", "Srilanka", sep='-')
# -> India-Pakistan-Nepal-Srilanka
How it works: sep is inserted between every pair of values passed to print() โ it has no effect if you only pass a single value.
end Parameter โ Controlling Line EndingsBy default, every print() call ends with a newline ('\n'), which is why consecutive print() calls each start on a new line:
print("Hello")
print("World")
# -> Hello
# -> World
Changing end to something other than '\n' (e.g., a space) makes the next print() output continue on the same line:
print("Hello", end=' ')
print("world")
# -> Hello world
How it works: end replaces the default trailing newline with whatever string you specify. Here, end=' ' means "add a space instead of moving to a new line," so the next print's output appears right after it on the same line.
print() SignatureInspecting print()'s docstring (e.g., via Jupyter's tooltip/inspector) reveals its full signature:
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
| Parameter | Default | Meaning |
|---|---|---|
value, ... | โ | One or more values to print |
sep | ' ' (space) | String inserted between multiple values |
end | '\n' (newline) | String appended after the last value |
file | sys.stdout | A file-like object (stream) to write to; defaults to the console |
flush | False | Whether to forcibly flush the output stream immediately |
Prints the values to a stream, or to sys.stdout (the console) by default.
print itself is described as builtin_function_or_method โ it's a function built directly into Python, not something you need to import.
# Basic printing
print("Hello World")
# Multiple values (default separator = space)
print("India", "Pakistan", "Nepal", "Srilanka")
# Custom separator
print("India", "Pakistan", "Nepal", "Srilanka", sep='/')
# Custom end (keeps output on the same line)
print("Hello", end=' ')
print("world")
print() accepts values of any type and multiple values at once.sep = what goes between values (default: space).end = what goes after the whole print statement (default: newline).end is the standard trick to prevent two print() calls from landing on separate lines.file and flush exist for advanced use (e.g., redirecting output to a file, or forcing immediate output) but weren't demonstrated with examples in this session.sep = ' ', default end = '\n'.sep only matters when printing multiple comma-separated values.end affects the next output's starting position, not the current line's content.print() displays values to the console. Pass multiple values separated by commas to print them on one line (joined by sep, default a space). Every print() call ends with a newline by default (end='\n'), which is why successive prints appear on separate lines โ override end (e.g., end=' ') to keep output on the same line instead. Full signature: print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False).