# Python 语言基础变量获得变量类型

**URL:** <https://www.isharkfly.com/t/python/13374>\
**Category:** 程序语言\
**Tags:** python\
**Created:** [March 7, 2021, 5:18pm UTC](https://www.isharkfly.com/t/python/13374 "2021-03-07T17:18:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [March 7, 2021, 5:18pm UTC](https://www.isharkfly.com/t/python/13374/1 "2021-03-07T17:18:05Z")

</div>

如果你对你 Python 使用的变量类型不是非常清楚的话，你可以使用函数 type 来获得变量的类型。

通常如果使用 IDE 的话，IDE 会告诉你的变量类型是什么。

考察下面的代码：

```python
x = 5
y = "John"
print(type(x))
print(type(y))

```

上面的代码将会输出

```plaintext
<class 'int'>
<class 'str'>

```

通过上面的输出内容，我们就非常容易明白在 Python 中你定义的变量使用的数据类型是什么。

![python-v-03](https://www.isharkfly.com/images/transparent.png)

如果我们使用 IDE 的调试模式的话，我们可以非常容易的在 IDE 中设置断点。

然后通过断点的查看数据类型来查看你定义的数据类型是什么。
