这里主要记录一下在 python 中使用单引号, 双引号 和三引号的区别.
当前开发环境
Python 3.5.2
GitHub
单引号
# import !/user/bin/env python
# -*- coding:UTF-8 -*-
string1 = 'hello world1'
print(string1)
运行结果
hello world1
双引号
# import !/user/bin/env python
# -*- coding:UTF-8 -*-
string2 = "hello world2"
print(string2)
运行结果
hello world2
三引号
# import !/user/bin/env python
# -*- coding:UTF-8 -*-
string3 = '''hello world3'''
print(string3)
运行结果
hello world3
目前为止,是看不出来它们之间的区别的, 都是 Python 的 String 类型表示方式之一.接下来看下它们的区别:
换行表示(不考虑字符串的拼接)
单引号
# import !/user/bin/env python
# -*- coding:UTF-8 -*-
string11 = 'hello world1' + \
' again'
print(string11)
运行结果
hello world1 again
双引号

本文详细介绍了Python中单引号、双引号和三引号的区别,包括字符串换行表示、注释使用以及混合引用的场景。通过示例代码展示了如何避免语法错误并正确使用引号。
最低0.47元/天 解锁文章
7281

被折叠的 条评论
为什么被折叠?



