How to use the print function in Python?
In Python, the print function is used to output specified values to the console.
Here is the basic usage:
print(value)
In this case, the value is the value to be printed, which can be a string, number, variable, etc. For example:
print("Hello, World!") # 打印字符串
print(123) # 打印数字
x = 5
print(x) # 打印变量的值
In addition, the print function also supports printing multiple values, which can be separated by commas.
print("Hello", "World!") # 打印多个值
Some common parameters and uses of the print function include:
- sep parameter: used to specify the separator between multiple values, default is a space.
- end parameter: specifies the character to be printed after the end, default is the newline character.
- File parameter: used to specify the file for printing output, defaulting to standard output (console).
For further details on usage, refer to the Python official documentation at: https://docs.python.org/3/library/functions.html#print