python中原始字符串和长字符串

python中原始字符串和长字符串

1、原始字符串

>>> string="c:\now"
>>> string
'c:\now'
>>> print(string)    ## \n被解释为换行符
c:
ow
>>> 

在字符串前添加r,表示原始字符串

>>> string = r"c:\now"
>>> string
'c:\\now'
>>> print(string)
c:\now

2、长字符串 , 三重引号表示长字符串,可以随意换行。

>>> print("""aaaaaa
bbbbbb
cccccc
dddddd
""")
aaaaaa
bbbbbb
cccccc
dddddd
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14714255.html