Home > Article > Backend Development > Detailed explanation of graphic code for line wrapping of print function in Python3
I was learning python3 recently and found a problem that I wanted to summarize. So the following article mainly introduces you to the relevant information about the line wrapping of the print function in Python 3. The article introduces it in detail through the example code and provides the necessary information. Friends, it has certain reference and learning value. Friends who are interested, please follow the editor to learn together.
Preface
Due to work needs, I recently looked at Python applications, starting with the entry-level multiplication table, and found that There are really big differences between Python3.
#Code in Python2. . There are two issues involved here: First, at the end of the
print() function in the inner loop, in Pyhon2,
print()
Figure 1
Running in Linux is shown in Figure 2,
Figure 2
It can be seen that, There is no line break. The reason is that in Python3, line break adopts new syntax, which is in the form of
print('*', end=”)
print() The second parameter of the function is added with end=", modified and run. The final running result is as shown in Figure 3,
Figure 3
Normal output.
xrange() function, if you just modified the
print() function syntax, if you don’t pay attention to
xrange()
##Figure 4
The prompt here says 'xrange' is not defined. In fact, in Python3, the xrange() function has been integrated into the
range()
range() function is used uniformly.
OK, after modification, the normal result in Figure 3 will be output.
Summarize
The above is the detailed content of Detailed explanation of graphic code for line wrapping of print function in Python3. For more information, please follow other related articles on the PHP Chinese website!