多行语句
Python 通常是一行写完一条语句,但如果语句很长,我们可以使用反斜杠 \ 来实现多行语句,例如:
duohang = item_one + \
item_two + \
item_three
复制代码
在 [], {}, 或 () 中的多行语句,不需要使用反斜杠 \,例如:
duohang = ['item_one', 'item_two', 'item_three',
'item_four', 'item_five']
复制代码
数字(Number)类型
python中数字有四种类型:整数、布尔型、浮点数和复数。
- int (整数), 如 1, 只有一种整数类型 int,表示为长整型
- bool (布尔), 如 True、false。
- float (浮点数), 如 1.23、3E-2
- complex (复数), 如 1 + 2j、 1.1 + 2.2j
字符串(String)
- python中单引号和双引号使用完全相同。
- 使用三引号(''' 或 """)可以指定一个多行字符串。
- 转义符 \
- 反斜杠可以用来转义,使用r可以让反斜杠不发生转义。
如 r"this is a line with \n" 则\n会显示,并不是换行。
<