编程语言
首页 > 编程语言> > python 面向对象专题(六):元类type、反射、函数与类的区别、特殊的双下方法

python 面向对象专题(六):元类type、反射、函数与类的区别、特殊的双下方法

作者:互联网

目录

 

1. 元类type

2. 反射

3. 函数与类的区别

           

from types import FunctionType
from types import MethodType
def func():
    pass
class A:
    def func(self):
        pass
obj = A()
print(isinstance(func,FunctionType))  # True
print(isinstance(A.func,FunctionType))  # True
print(isinstance(obj.func,FunctionType))  # False
print(isinstance(obj.func,MethodType))  # True

 

4. 特殊的双下方法

标签:__,obj,name,python,self,双下,元类,print,def
来源: https://www.cnblogs.com/qiu-hua/p/12862265.html