> 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.md).

# 类型

## 变量

python中使用变量是不需要提前定义的，在使用时直接赋值即可，其类型也会自动推断。且变量可以服务任何类型值。如下的赋值方式是合法的：

```
>>> a = 1
>>> a = True
>>> a = "abc"
```

{% hint style="info" %}
如果使用一个未赋值的变量会引发错误
{% endhint %}

```
>>> n
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined
```
