你不一定知道的单引号,双引号用法
print(A fellow doesn't last long on what he has done. He's got to keep on delivering as he goes along.) #输出会报错,因为这句话中存在两个单引号
但你只需在你要输出的句子前后分别加三个单引号或者三个双引号就能解决这一难题
print('''A fellow doesn't last long on what he has done. He's got to keep on delivering as he goes along.''') print("""A fellow doesn't last long on what he has done. He's got to keep on delivering as he goes along.""") #输出:A fellow doesn't last long on what he has done. # He's got to keep on delivering as he goes along.
你不一定知道的转义字符的用法
转义字符()
print('n') #输出: #打印换行 print('\n') #输出:n print('\n') #输出: #打印一个和换行 print('\n') #输出:\n print('\') #输出:
原始字符串
我们不想让转义字符生效,我们只想显示字符串本来的意思,这就要用r和R来定义原始字符串
print(r'n') #输出:n print(R'\n') #输出:\n print(r"A fellow doesn't last long on what he has done. He's got to keep on delivering as he goes along.") #同样生效 #输出:A fellow doesn't last long on what he has done. He's got to keep on delivering as he goes along.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)