> For the complete documentation index, see [llms.txt](https://minghuiwu.gitbook.io/tfbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://minghuiwu.gitbook.io/tfbook/fu-lu-2-gong-yu-shan-qi-shi-bi-xian-li-qi-qi-jian-ming-python-ji-chu/fu-lu-1-gong-yu-shan-qi-shi-bi-xian-li-qi-qi-jian-ming-python-ji-chu/2.2-bian-liang.md).

# 2.2 变量

每个变量在内存中创建，都包括变量的标识、名称和数据这些信息。

每个变量在使用前都必须赋值，赋值号是“=”

在Python中定义变量的时候不需要指明数据类型，所以直接写变量名就可以了，Python语言会自动根据你所赋的值的类型来决定它的数据类型，这也是它和其他程序设计语言的不同。

![图2-7](blob:https://minghuiwu.gitbook.io/7c847e8b-5c35-4b65-a241-4032f4992bfc)

如果我们想知道这些变量具体的数据类型，可以用“type（变量名）”来实现。

![图2-8](blob:https://minghuiwu.gitbook.io/578214af-4a46-4f86-8dca-b4b2497166fb)

这样我们就可以看到变量int\_a的值为5，数据类型是int。

由于我们现在在Jupyter中，每执行一行语句后面都要新增一个单元输入语句，所以我们可以用Shift+Enter键来执行。这样它就会执行当前的单元并进入下一个单元，如果后面没有的话，就会新增一个单元，也就是下图的样子。

![图2-9](blob:https://minghuiwu.gitbook.io/9e84d3d3-bc1a-480f-9eb5-207285ea8c3e)

## > 示例代码

{% code title="1.py" %}

```python
int_a = 5
float_b = 6.3
str_c = "Hello"

print(int_a, float_b, str_c)
```

{% endcode %}

{% code title="2.py" %}

```python
print(int_a, type(int_a))
```

{% endcode %}

{% code title="3.py" %}

```python
print(float_b, type(float_b))
```

{% endcode %}
