1. raw 字符串
描述
如果一个字符串包含很多需要转义的字符,对每一个字符都进行转义会很麻烦。
为了避免这种情况,我们可以在字符串前面加个前缀 r,表示这是一个 raw 字符串,里面的字符就不需要转义了。
实例
print('\n(~_~)/ \(~_~)n/')
(~_~)/ \(~_~)n/
print(r'\n(~_~)/ \(~_~)n/')
\n(~_~)/ \(~_~)n/
2. 多行字符串表示
描述
如果要表示多行字符串,可以用”’…”’表示:
”’Line 1
Line 2
Line 3”’
等价于:
‘Line 1\nLine 2\nLine 3’
还可以在多行字符串前面添加 r ,把这个多行字符串也变成一个raw字符串:
print(r'''Python is created by "Guido".
It is free and easy to learn.
Let's start

最低0.47元/天 解锁文章
2461

被折叠的 条评论
为什么被折叠?



