Python 字符串換行的多種方式
更新時間:2018年09月06日 10:03:58 作者:寒爵
本文通過四種方法給大家介紹了Python 字符串換行的方式,在文中最下面通過代碼給大家介紹了python代碼過長的換行方法,需要的朋友可以參考下
第一種:
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>'
第二種:
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>'
第三種:
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>')
第四種:
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>'''
下面看下python代碼過長的換行
python代碼換行就是每行后面加個 \
舉個栗子:
time = "2017" print "one" + "," \ + "two" \ + ",three" + \ "," + time
打印出來就是:
one,two,three,2017
再舉一個栗子:
print "this line is toooooooooooo \ long"
打印出來:
this line is toooooooooooo long
總結
以上所述是小編給大家介紹的Python 字符串換行的多種方式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
python 處理telnet返回的More,以及get想要的那個參數方法
今天小編就為大家分享一篇python 處理telnet返回的More,以及get想要的那個參數方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02Python使用pyautogui模塊實現自動化鼠標和鍵盤操作示例
這篇文章主要介紹了Python使用pyautogui模塊實現自動化鼠標和鍵盤操作,簡單描述了pyautogui模塊的功能,并結合實例形式較為詳細的分析了Python使用pyautogui模塊實現鼠標與鍵盤自動化操作相關技巧,需要的朋友可以參考下2018-09-09