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

566次阅读
没有评论

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

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

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

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-06-21发表,共计552字。
新手QQ群:570568346,欢迎进群讨论 Python51学习