栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python中你需要掌握的小细节

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python中你需要掌握的小细节

你不一定知道的单引号,双引号用法

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.
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/499188.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号