Python print() functie
Definition and Usage
The print() function prints the specified message to the screen or other standard output devices.
The message can be a string or any other object, which will be converted to a string before being written to the screen.
Syntax
print(object(s), separator=separator, end=end, file=file, flush=flush)
Parameter Value
Parameter | Description |
---|---|
object(s) | Any object, and any number. Convert to string before printing. |
sep='separator' | Optional. Specify how to separate objects if there are multiple objects. The default value is ' '. |
end='end' | Optional. Optional. Specify the content to be printed at the end. The default value is '\n' (newline). |
file | Optional. Object with write methods. The default is sys.stdout. |
flush | Optional. Boolean value, specifying whether the output is refreshed (True) or buffered (False). The default is False. |
More Examples
Example
Print multiple objects:
print("Hello", "how are you?")
Example
Print tuple:
x = ("apple", "banana", "cherry") print(x)
Example
Print two messages and specify the separator:
print("Hello", "how are you?", sep=" ---")