Python语言特性-Python自省

Python的自省是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

猜你喜欢

转载自blog.csdn.net/weixin_42943975/article/details/83241447