Realization of Python code with too long line break

  • 2021-07-10 20:01:10
  • OfStack

Add\ or Enter at the end, enter and use it depending on the situation,\ general.

For print string wrap, you can add three single quotes or three double quotes, but the carriage return wrap will be preserved. To render a string without wrap, you can add\ at the end of each line in the quotes, or use double quotes for the string, with parentheses around the double quotes ()

Three Ways of python String Wrap


if __name__ == '__main__':
 # No. 1 1 Species:  3 Single quotation marks 

  print ''' aaaaaaaaaaaaaaaa
     bbbbbbbbbbbbbb'''

# No. 1 2 Species:  3 Double quotation marks 
  print """ aaaaaaaaaaaaaaaa
     bbbbbbbbbbbbbb"""

# No. 1 3 Species:  \ End  

  print "aaaaaaaaaaaaaaaa , \
     bbbbbbbbbbbbbb"

python code wrapping is to add a\ after each line

Take chestnuts:


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

Printed out is:

one,two,three,2017

Another chestnut:


print "this line is toooooooooooo \
long"

Print out:

this line is toooooooooooo long


Related articles: