【python】字符串变量赋值时字符串可用单或双引号

 >>> name='萧峰'
>>> print(name)
萧峰
>>> name="独孤求败"
>>> print(name)
独孤求败
>>>
 >>> p='C:\Users\lenovo\Desktop\python'
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
>>> p='C:\\Users\\lenovo\\Desktop\\python'
>>> p
'C:\\Users\\lenovo\\Desktop\\python'
>>> p=r'C:\Users\lenovo\Desktop\python'
>>> p
'C:\\Users\\lenovo\\Desktop\\python'
>>> p=r'C:\Users\lenovo\Desktop\python\'
SyntaxError: EOL while scanning string literal
>>> p=r'C:\Users\lenovo\Desktop\python'+'\\'
>>> p
'C:\\Users\\lenovo\\Desktop\\python\\'
>>> p=r'C:\Users\lenovo\Desktop\python'+'\'
SyntaxError: EOL while scanning string literal
>>> p='C:\\Users\\lenovo\\Desktop\\python\\'
>>> p
'C:\\Users\\lenovo\\Desktop\\python\\'
>>> print(p)
C:\Users\lenovo\Desktop\python\
>>> poem='''滚滚长江东逝水
浪花涛尽英雄
'''
>>> poem
'滚滚长江东逝水\n浪花涛尽英雄\n'
>>> print(poem)
滚滚长江东逝水
浪花涛尽英雄 >>> poem="""青山依旧在
几度夕阳红"""
>>> poem
'青山依旧在\n几度夕阳红'
>>> print(poem)
青山依旧在
几度夕阳红
>>>
上一篇:Thrift-0.10.0 CenOS 7 编译错误 error: expected ')' before 'PRIu32'


下一篇:Luogu3763 TJOI2017 DNA NTT/SA