首页 › 参考手册 › 内置函数 › type()

Python type() 函数

描述

返回对象的类型。判断类型时更推荐使用 isinstance(),因为它同时考虑了继承关系。

语法

type(object)

参数

参数说明
object任意对象

返回值

类型对象

实例

for v in [1, 1.0, "1", [1], (1,), {1}, {"a": 1}, None]:
    print(repr(v), type(v).__name__)
以上实例输出结果为:
1 int
1.0 float
'1' str
[1] list
(1,) tuple
{1} set
{'a': 1} dict
None NoneType