Python print() Function: Understanding and Using the 'end' Parameter
The 'end' parameter in Python is used to specify what character or string should be used to separate multiple outputs.
By default, the 'print()' function in Python adds a newline character ('\n') at the end of each output. However, if you want to customize the separator character or string, you can use the 'end' parameter.
For example, if you want to print multiple strings on the same line with a space separator, you can set 'end=" "':
print("Hello", "world", end=" ")
print("Python")
Output:
Hello world Python
If you want to suppress the newline character and print multiple outputs on the same line, you can set 'end="":
print("Hello", end="")
print("world")
Output:
Helloworld
原文地址: https://www.cveoy.top/t/topic/mQVq 著作权归作者所有。请勿转载和采集!