您的位置:首页 > 编程语言 > Python开发

Python基础 (3) - String, Long String, Raw String

2008-09-15 13:10 441 查看
我喜欢用例子说明,语文不是很好-_-,直接看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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: