晴川云Python教程:Python中如何判断值的类型

python中可以使用type()方法获取对象的类型。

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'>

原创文章,作者:晴川运维,如若转载,请注明出处:https://baike.qcidc.com/14540.html

(0)
晴川运维晴川运维
上一篇 2025年10月6日
下一篇 2025年10月6日

相关推荐

发表回复

登录后才能评论