The keyword end can be used to output the results to the same line, or to add different characters at the end of the output.
Grammar:
(Recommended learning: Python video tutorial)
print("\t",end='')
Including end='' as an argument to the print() BIF turns off the function's default behavior of automatically including newlines in output.
The principle is: pass an empty string for end, so that the print function does not add a newline character to the end of the string, but adds an empty string.
This is only useful for Python3.
Example:
a, b = 0, 1while b < 1000: print(b, end=',') a, b = b, a+b
Execute the above program, the output result is:
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
Example:
list = [1,2,3] for i in list: print(i,end='') >>>123
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to use end in python. For more information, please follow other related articles on the PHP Chinese website!