'''是怎么用的?求教!
>>> pystr = '''python
... is cool'''
>>> pystr
'python\nis cool'
>>> print pystr
python
is cool
[解决办法]
'''三引号一般用来定义多行字符串,从'''开始,直到碰到'''结束,中间所有字符(包括换行)都是字符串内容,无需转义字符
看测试
>>> s = '''this is a testof multiline string, includingspecial characters like *,',",\,/,...,!,`,etc.even 中文字符 is acceptable.'''>>> s'this is a test\nof multiline string, including\nspecial characters like *,\',",\n\\,/,...,!,`,etc.\neven \xd6\xd0\xce\xc4\xd7\xd6\xb7\xfb is acceptable.\n'>>> print sthis is a testof multiline string, includingspecial characters like *,',",\,/,...,!,`,etc.even 中文字符 is acceptable.>>>
[解决办法]
你会发现,在三引号表示的字符串中,特殊字符会被自动转义,非常好使