Application of Python output log print function (python column 001)

insert image description here

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)
  • *objectsRepresents one or more objects to output
  • sepIndicates the separator between each object, the default is a space
  • endIndicates the end character after the output, the default is a newline character\n
  • fileparameter can write the output to the specified file instead of the standard output device.
  • flushThe 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 septhe parameter to customize the separator between multiple objects, for example:

x = 3
y = 4
print(x, y, sep=':')  # 输出:3:4

The above code uses septhe parameter to change the separator between the output two integers to a colon :, and the output result is "3:4".

Guess you like

Origin blog.csdn.net/zl18603543572/article/details/130415299