Home  >  Article  >  Backend Development  >  How to use end in python

How to use end in python

(*-*)浩
(*-*)浩Original
2019-07-20 10:20:0147231browse

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.

How to use end in python

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=&#39;,&#39;)
    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=&#39;&#39;)
>>>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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn