品易云推流 关闭
文章详情页
文章 > Python基础教程 > python中双引号和单引号的区别是什么

python中双引号和单引号的区别是什么

头像

爱喝马黛茶的安东尼

2019-10-28 16:24:5710350浏览 · 0收藏 · 0评论

python3中的单引号‘’和双引号“”的作用一样。

3个单引号的作用:

1、表示注释

#3个单引号表示注释多行
'''
gf_of_archerzon = "Wang"
print("archerzon的女盆友是",gf_of_archerzon)
print("archerzon的女盆友是%s"%gf_of_archerzon)
'''

相关推荐:《Python基础教程

2、表示多行打印

msg='''
gf_of_archerzon = "Wang"
print("archerzon的女盆友是",gf_of_archerzon)
print("archerzon的女盆友是%s"%gf_of_archerzon)
'''

输出:

gf_of_archerzon = "Wang"
print("archerzon的女盆友是",gf_of_archerzon)
print("archerzon的女盆友是%s"%gf_of_archerzon)

有点小技巧倒是可以提一下,如:

str = 'my name is "xxx"!'
str = "my name is 'xxx'!"

这样各自的赋值包含不同的引号。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图