r‘‘‘ ’’’ 與‘‘‘ ’” 有 什么區(qū)別呢
>>> 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.
2020-10-21
r'''...'''會對'''...'''中的內(nèi)容進行轉(zhuǎn)義
單獨的'''...''',就只是一個換行的作用
2020-10-18
>>> 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.
注意這兩個輸出的內(nèi)容有區(qū)別,第一個輸出的to be or not to be是帶有雙引號的,第二個沒有。
第一個print的內(nèi)容因為即有雙引號"To be, or not to be",又有單引號it's,因為在print的時候需要對內(nèi)容中的引號進行轉(zhuǎn)義,使用轉(zhuǎn)義符號\,涉及到換行的時候使用\n
第二個print的內(nèi)容是沒有雙引號,只有單引號的,這種情況下不需要對引號進行轉(zhuǎn)義,就可以輸出,只需要使用'''...'''來進行轉(zhuǎn)行。如果第二個print的內(nèi)容跟第一個一樣,即有雙引號又有單引號,那么你只使用'''...'''恐怕打印不出想要的內(nèi)容
由于轉(zhuǎn)義符號用起來比較麻煩,我們有一個相對簡單的工具,叫raw字符串,即r'...',它表示對引號內(nèi)的內(nèi)容進行轉(zhuǎn)義,即告訴計算機,你甭管引號里是什么內(nèi)容了,直接依原樣輸出為字符串。當然raw字符串也可以搭配'''...'''來使用,即多增加了一個轉(zhuǎn)行的效果。r'''...'''的作用是對引號內(nèi)的內(nèi)容進行轉(zhuǎn)行并轉(zhuǎn)義。
'''...'''的作用只是對內(nèi)容進行轉(zhuǎn)行,如果涉及到需要轉(zhuǎn)義的情況,它是完不成的。