The print()
function in Python is a built-in function used to display the specified content, such as variables, strings, or numbers, on the output screen. It outputs the values passed as arguments to the function, separated by spaces by default.
Parameter Values
Parameter | Description |
---|---|
object(s) | Any object(s) to be printed. Non-keyword arguments are converted to strings and written to the standard output file. |
sep | Objects are separated by sep. Default is ' ' |
end | String appended after the last value, default is a newline. |
file |
|
flush | Whether to forcibly flush the stream. |
Return Values
The print()
function in Python doesn't return any value; it returns None
.
How to Use print()
in Python
The print()
function in Python is used to display the specified message or variable values in the output console.
print('Hello, world!')
You can use the print()
function to concatenate strings with other data types like integers or floats.
name = 'Alice'
age = 30
print('My name is', name, 'and I am', age, 'years old')
The print()
function has parameters such as end and sep to customize the output format.
print('apple', 'orange', 'banana', sep=', ', end='.')