The role of end=' ' in the python statement

The role of end=' ' in the python statement

print defaults to printing one line with a newline at the end. end=' ' means no newline at the end, add a space. The number of spaces depends on the number of spaces inside the quotes

The following example illustrates:
without adding end="", print out the URL http://c.biancheng.net/python/

str="http://c.biancheng.net/python/"
i = 0
while i<len(str):
    print(str[i]) 
    i+=1

insert image description hereIt can be clearly seen that the print output is printed in a separate line after a line break

Then we add end="" and print out the URL http://c.biancheng.net/python/.
insert image description here
It is obvious that the URL is completely printed after the output is printed.

end=' ', the number of spaces in the quotation marks determines the gap between the printouts, as shown in the figure below
insert image description here

Guess you like

Origin blog.csdn.net/weixin_42694422/article/details/117957573