首页 > 文章列表 > python中双引号和单引号的区别是什么

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

Python 单引号 区别 双引号
234 2022-08-07

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

3个单引号的作用:

1、表示注释

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

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'!"

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