1. 程式人生 > >python學習-轉義字元\

python學習-轉義字元\

轉義字元(\)的應用包含兩種情況:一是輸出字串中包含單引號,如輸出what's your name?,這個時候用單引號指示它,python會不知道從何處結束,這個時候可以加入轉義符即‘what\'s your name?’或者換成雙引號“what's your name?”

二是在一句話的後面,表示該句不分段,如:

"This is the first sentence.\
This is the second sentence."

等價於"This is the first sentence. This is the second sentence."