专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Perl/Python

'''是如何用的?求教

发布时间:2011-06-29 20:11:29 文章来源:www.iduyao.cn 采编人员:星星草
'''是怎么用的?求教!
>>> 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.

>>>

------解决方案--------------------
你会发现,在三引号表示的字符串中,特殊字符会被自动转义,非常好使
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: