Home > Backend Development > Python Tutorial > How to use end in python

How to use end in python

(*-*)浩
Release: 2019-07-20 10:20:01
Original
47261 people have browsed it

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='')
Copy after login

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
Copy after login

Execute the above program, the output result is:

1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
Copy after login

Example:

list = [1,2,3]

for i in list:
    print(i,end=&#39;&#39;)
>>>123
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template