亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

r‘‘‘ ’’’ 與‘‘‘ ’” 有 什么區別呢

>>> print('''how are you \*_*/

... I'm fine

... and you ?''')

how are you \*_*/

I'm fine

and you ?

>>> print('\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.')

"To be, or not to be": that is the question.

Whether it's nobler in the mind to suffer.

>>> print(''' To be ,or not to be :that is a question.

... Whether it's nobler int her mind to suffer.''')

?To be ,or not to be :that is a question.

Whether it's nobler int her mind to suffer.


正在回答

2 回答

r'''...'''會對'''...'''中的內容進行轉義

單獨的'''...''',就只是一個換行的作用

http://img1.sycdn.imooc.com//5f8fafde0001948312580512.jpg

0 回復 有任何疑惑可以回復我~

>>> print('\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.')

"To be, or not to be": that is the question.

Whether it's nobler in the mind to suffer.

>>> print(''' To be ,or not to be :that is a question.

... Whether it's nobler int her mind to suffer.''')

?To be ,or not to be :that is a question.

Whether it's nobler int her mind to suffer.

注意這兩個輸出的內容有區別,第一個輸出的to be or not to be是帶有雙引號的,第二個沒有。

第一個print的內容因為即有雙引號"To be, or not to be",又有單引號it's,因為在print的時候需要對內容中的引號進行轉義,使用轉義符號\,涉及到換行的時候使用\n

第二個print的內容是沒有雙引號,只有單引號的,這種情況下不需要對引號進行轉義,就可以輸出,只需要使用'''...'''來進行轉行。如果第二個print的內容跟第一個一樣,即有雙引號又有單引號,那么你只使用'''...'''恐怕打印不出想要的內容

由于轉義符號用起來比較麻煩,我們有一個相對簡單的工具,叫raw字符串,即r'...',它表示對引號內的內容進行轉義,即告訴計算機,你甭管引號里是什么內容了,直接依原樣輸出為字符串。當然raw字符串也可以搭配'''...'''來使用,即多增加了一個轉行的效果。r'''...'''的作用是對引號內的內容進行轉行并轉義。

'''...'''的作用只是對內容進行轉行,如果涉及到需要轉義的情況,它是完不成的。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

r‘‘‘ ’’’ 與‘‘‘ ’” 有 什么區別呢

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號