How is the ‘end’ function used in Python?

In Python, the ‘end’ parameter is used to specify the ending character for the print() function. By default, the print() function automatically adds a new line after printing an object. However, by using the ‘end’ parameter, we can customize the ending character instead of the default new line character \n.

The end parameter can accept any string as an argument to specify the character to print at the end of the print() function. For example:

print("Hello", end="!")  # 输出:Hello!
print("World", end="***")  # 输出:World***

In the example above, the first print() function uses end=”!”, so after printing, the exclamation mark is printed after “Hello”. The second print() function uses end=”***”, so after printing, the stars are printed after “World”.

bannerAds