python里怎么查看数据类型


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

# 一个参数实例

>>> type(1)

<type 'int'>

>>> type('school')

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

type() 与 isinstance()区别:

1

2

3

4

5

6

7

8

class A:

pass

class B(A):

pass

isinstance(A(), A) # returns True

type(A()) == A # returns True

isinstance(B(), A) # returns True

type(B()) == A # returns False

推荐:《python教程》

以上就是python里怎么查看数据类型的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python如何判断闰年

如何使用Python的requests包实现模拟登陆

Python 3.7新功能之dataclass装饰器详解

vb和Python哪个速度快

Python字典可变吗

Python装饰器之property()教程详解

介绍Python学习有了列表,为什么还有元组?

Python怎么删除

Python数组和列表区别

Python可以做游戏辅助吗

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...