代码点读机 / Python / type

type Python · 内置函数

看看一个值是什么类型,像看快递面单:上面写着它是文件、衣服还是电子产品。

怎么用

type(值)

小例子

print(type(42))
print(type('hi'))
print(type([]))

运行结果

<class 'int'>
<class 'str'>
<class 'list'>

官方文档:https://docs.python.org/zh-cn/3/library/functions.html#type

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条