Skip to main content

print()

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

file must be an object with a write(string) method; if it is not present or None, sys.stdout will be used.

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

Example 1:

The print() function in Python is used to display the specified message or variable values in the output console.

print('Hello, world!')
Example 2:

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')
Example 3:

The print() function has parameters such as end and sep to customize the output format.

print('apple', 'orange', 'banana', sep=', ', end='.')