1、python本身使用\來轉義一些特殊字符,例如在字串中加入引號的時候
s = 'i\'m superman' print(s) # i'm superman
2、Python中反斜線也可以用在一行結尾做續行符使用。
範例:
hello = "This is a rather long string containing\n\ several lines of text just as you would do in C.\n\ Note that whitespace at the beginning of the line is\ significant." print(hello)
注意,其中的換行符號仍然要使用 \n 表示-反斜線後的換行符號被丟棄了。以上範例將如下輸出:
This is a rather long string containing several lines of text just as you would do in C. Note that whitespace at the beginning of the line is significant.
Python中的轉義字元:
#更多Python相關技術文章,請造訪 Python教學欄位進行學習!
以上是python中反斜線是什麼意思的詳細內容。更多資訊請關注PHP中文網其他相關文章!