Python中如何判断值的类型
发布时间:2026-04-13 15:37:59

type()方法可用于python中获取对象的类型。
type() 如果您只有第一个参数,则返回对象类型,三个参数返回新类型对象。
以下是 type() 语法方法:语法方法:
type(object) type(name,bases,dict)
参数
name -- 类的名称。
bases -- 基类元组。
dict -- 类中定义的命名空间变量字典。
>>>type(1)
<type'int'>
>>>type('runoob')
<type'str'>
>>>type([2])
<type'list'>
>>>type({0:'zero'})
<type'dict'>请关注Python视频教程栏目,了解更多Python知识。
