>>> palindrome = 'A man,\nA plan,\nA canal:\nPanama.'
>>> print(palindrome)
A man,
A plan,
A canal:
Panama.
转义序列
\t
(
tab
)可用于对齐文本:
>>> print('\tabc')
abc
>>> print('a\tbc')
a bc
>>> print('ab\tc')
ab c
>>> print('abc\t')
abc
(最后一个字符串在行尾有一个你看不到的制表符。)
可能还需要在以相同字符引用的字符串内使用
\'
或
\"
指定字面单引号或双引号:
1
>>> testimony = "\"I did nothing!\" he said. \"Or that other thing.\""
>>> testimony
'"I did nothing!" he said. "Or that other thing."'
>>> print(testimony)
"I did nothing!" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.