我喜欢用例子说明,语文不是很好-_-,直接看code吧
长String,可以用 '''.......'''来定义,或者"""......"""
>>> print '''This is really a long Sting, I want to play but I have no time python is good, show a "hello world" end''' This is really a long Sting, I want to play but I have no time python is good, show a "hello world" end
当在想在输入时换行,而显示时不换行的话,就在一行末加上"/"(没有引号)
看code吧
>>>print "hello, /
world"
hello, world
>>> print /
"hello world"
hello world
>>> 1+2+3/
+4+5
15
Raw string
还是看code先
>>> print 'Hello, /nworld' Hello, world >>> print "hello, /nworld" hello, world >>> t = "hello, /nworld" >>> t 'hello, /nworld' >>> print t hello, world >>> print r'"hello /nworld"' "hello /nworld"
其中print r'...'就是print 原始的string.
本文通过实例讲解了Python中处理长字符串的方法,包括使用不同符号定义长字符串、如何在字符串中实现换行显示效果以及如何使用原始字符串避免转义。
980

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



