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

 

posted @ 2021-04-28 15:18  小鲨鱼2018  阅读(249)  评论(0编辑  收藏  举报