品易云推流 关闭
文章详情页
文章 > Python常见问题 > Python中如何判断值的类型

Python中如何判断值的类型

头像

yang

2020-05-11 15:51:593171浏览 · 0收藏 · 0评论

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

更多Python知识请关注Python视频教程栏目。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图