In Python, the print() function is a function used to output content to the standard output device, usually used to debug programs and display program running results
Use it directly as follows:
print(5)
print("早起的年轻人")
The print() function can accept multiple parameters, separate them with spaces, and output to the standard output device.
The print() function can also combine multiple parameters into a string and output it.
The common syntax of the print() function is as follows:
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
*objects
Represents one or more objects to outputsep
Indicates the separator between each object, the default is a spaceend
Indicates the end character after the output, the default is a newline character\n
file
parameter can write the output to the specified file instead of the standard output device.flush
The parameter indicates whether to refresh the cache immediately, and the default is False.
For example, we can use the print() function to output a string and an integer as follows:
name = 'Alice'
age = 20
print('My name is', name, 'and I am', age, 'years old.') # 输出:My name is Alice and I am 20 years old.
The above code uses the print() function to output a string and an integer, and uses the default parameters to combine them into a string and output it to the standard output device.
In addition, we can use sep
the parameter to customize the separator between multiple objects, for example:
x = 3
y = 4
print(x, y, sep=':') # 输出:3:4
The above code uses sep
the parameter to change the separator between the output two integers to a colon :
, and the output result is "3:4".