當(dāng)需要在字符串中使用特殊字符時(shí),我們需要用到python中的反斜杠()轉(zhuǎn)義字符蛹锰。下面介紹幾個(gè)餐飲的轉(zhuǎn)義符:
\:反斜杠符號(hào)
print('2.Amy got up late, and she said "I miss the breakfast,this monring"')#\\是單斜杠
輸出結(jié)果如下:image.png
\':?jiǎn)我?hào)
print('4.Amy got up late, and she said \'I miss the breakfast,this monring\'')#\\是單引號(hào)
輸出結(jié)果如下:image.png
\":雙引號(hào)
print("3.Amy got up late, and she said \"I miss the breakfast,this monring\"")#\"是雙引號(hào)
輸出結(jié)果如下:image.png
\a:響鈴
print('5.Amy got up late, \aand she said "I miss the breakfast,this monring"')#\a是響鈴符
輸出結(jié)果如下(會(huì)有響鈴聲):image.png
\b:退格(Backspace)
print('6.Amy got up late, \band she said "I miss the breakfast,this monring"')#\b是退格符
輸出結(jié)果如下:image.png
\n:換行
print('8.Amy got up late, \nand she said "I miss the breakfast,this monring"')#\n是換行符
輸出結(jié)果如下:\v:縱向制表符
print('10.Amy got up late, \vand she said "I miss the breakfast,this monring"')#\v是垂直制表符
輸出結(jié)果如下:image.png
\t:橫向制表符
print('\t1.Amy got up late, and she said "I miss the breakfast,this monring"')#\t是tab
輸出結(jié)果如下:image.png
\r:回車
print('9.Amy got up late, \rand she said "I miss the breakfast,this monring"')#\r是回車
輸出結(jié)果如下:image.png
\f:換頁(yè)
print('7.Amy got up late, \fand she said "I miss the breakfast,this monring"')#\f是換頁(yè)
輸出結(jié)果如下:image.png
\xyy:十六進(jìn)制數(shù)届搁,yy代表的字符蕊爵,例如:\x0a代表?yè)Q行
\other:其它的字符以普通格式輸出