>>> pystr = '''python
... is cool'''
>>> pystr
'python\nis cool'
>>> print pystr
python
is cool
------解决方案--------------------
'''三引号一般用来定义多行字符串,从'''开始,直到碰到'''结束,中间所有字符(包括换行)都是字符串内容,无需转义字符
看测试
- Python code
>>> s = '''this is a test of multiline string, including special 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 s this is a test of multiline string, including special characters like *,',", \,/,...,!,`,etc. even 中文字符 is acceptable. >>>
------解决方案--------------------
你会发现,在三引号表示的字符串中,特殊字符会被自动转义,非常好使