本文摘自php中文网,作者(*-*)浩,侵删。
type() 函数如果你只有第一个参数则返回对象的类型,三个参数返回新的类型对象。
type():不会认为子类是父类(推荐学习:Python视频教程)
以下是 type() 方法的语法:
1 | class type(name, bases, dict)
|
参数
name -- 类的名称。bases -- 基类的元组。dict -- 字典,类内定义的命名空间变量。
返回值
一个参数返回对象类型, 三个参数,返回新的类型对象。
以下展示了使用 type 函数的实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # 一个参数实例
>>> type(1)
<type 'int' >
>>> type( 'runoob' )
<type 'str' >
>>> type([2])
<type 'list' >
>>> type({0: 'zero' })
<type 'dict' >
>>> x = 1
>>> type( x ) == int # 判断类型是否相等
True
# 三个参数
>>> class X(object):
... a = 1
...
>>> X = type( 'X' , (object,), dict(a=1)) # 产生一个新的类型 X
>>> X
< class '__main__.X' >
|
更多Python相关技术文章,请访问Python教程栏目进行学习!
以上就是python怎么看数据类型的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
大学有Python课吗
Python中的sample什么意思
Python color怎么设置
快速了解Python的数据类型有哪四种
Python2和Python3字符串区别
Python的除法运算符是什么意思
Python中有map方法吗
看看 Python django开发 异常及解决办法
Python实现管理站点的方法
Python提供了哪三种方法用于读取文本文件的内容?
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python怎么看数据类型