SoFunction
Updated on 2024-11-14

Python String Line Breaks in Various Ways

The first:

x0 = '<?xml version="1.0"?>' \
   '<ol>' \
   ' <li><a href="/python" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Python</a></li>' \
   ' <li><a href="/ruby" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Ruby</a></li>' \
   '</ol>'

The second:

x1 = '<?xml version="1.0"?> \
<ol> \
  <li><a href="/python" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Python</a></li> \
  <li><a href="/ruby" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Ruby</a></li> \
</ol>'

The third:

x2 = ('<?xml version="1.0"?>'
   '<ol>'
   ' <li><a href="/python" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Python</a></li>'
   ' <li><a href="/ruby" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Ruby</a></li>'
   '</ol>')

The fourth:

x3 = '''<?xml version="1.0"?>
<ol>
  <li><a href="/python" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Python</a></li>
  <li><a href="/ruby" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Ruby</a></li>
</ol>'''

Here's a look at python code with excessively long line breaks

A line break in python code is when each line is followed by a \

Take a chestnut:

time = "2017"
 print "one" + "," \
 + "two" \
 + ",three" + \
 "," + time

Printing it out is:

one,two,three,2017

Another chestnut:

print "this line is toooooooooooo \
 long"

Print out:

this line is toooooooooooo long

summarize

The above is a small introduction to the Python string line breaks in a variety of ways, I hope to help you, if you have any questions please leave me a message, I will reply to you in a timely manner. Here also thank you very much for your support of my website!