python字符串

1.长字符串 当一个字符串要横跨多行时,可以用三个单引号或双引号,这时,字符串中若有单引号或双引号不用转义的反斜线。如果不用3单引号或3双引号,可以使用反斜线,例子如下:

#使用反斜线
print "hello \
world!"

#3双引号
print """hello,
jack!hello,
python!"""

#3单引号
print '''hello,
jack!hello,
python!'''
2.如果不希望反斜线转义,有如下两种方法:

#1.通过双反斜线实现
print 'hhhhh\\aaaaaa'

#2.通过原始字符串实现,以r开头
print r'c:\program files\fonds\aaaaa\eee'


你可能感兴趣的:(python字符串)