> For the complete documentation index, see [llms.txt](https://viva.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://viva.gitbook.io/project/kai-fa/python/an-zhuang/shu-zi.md).

# 数字

python中支持的数字类型有：`int`（整型），`float`（浮点型）和`complex`(复数)。

支持的运算符有`+`（加法），`-`（减法），`*`（乘法），`/`（除法），`%`（求余），`**`（乘方）。其中除法永远返回浮点型值，如果需要去除小数部分可以使用`//`。当整型与浮点型一同运算时会转换为浮点型。

```
>>> 1 + 1
2
>>> 3 - 2
1
>>> 3 * 2
6
>>> 12 / 3
4.0
>>> 13 // 4
3
>>> 13 % 4
1
>>> 2 ** 8
256
>>> 3+5j - 2+1j
(1+6j)
```

使用`()`可以控制运算表达式中各个块的优先级

```
>>> 3 * (1 + 2)
9
```

与大多数编程语言相似，浮点型不是绝对精确的，存在一定的精度误差

```
>>> 3 - 2.2
0.7999999999999998
```
