首页 > 编程语言 > 详细

Python自省

时间:2018-11-10 10:33:50      阅读:112      评论:0      收藏:0      [点我收藏+]

 

这个也是python彪悍的特性.

自省就是面向对象的语言所写的程序在运行时,所能知道对象的类型.简单一句就是运行时能够获得对象的类型.比如type(),dir(),getattr(),hasattr(),isinstance().

a = [1,2,3]
b = {‘a‘:1,‘b‘:2,‘c‘:3}
c = True
print type(a),type(b),type(c) # <type ‘list‘> <type ‘dict‘> <type ‘bool‘>
print isinstance(a,list)  # True

Python自省

原文:https://www.cnblogs.com/sea-stream/p/9937838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!