函数、方法区别
- 函數和方法?
class Foo(object): def __init__(self): self.name = 'alex' def func(self): print(self.name)from types import FunctionType,MethodTypeobj = Foo() print(isinstance(obj.func,FunctionType)) # False print(isinstance(obj.func,MethodType)) # Trueprint(isinstance(Foo.func,FunctionType)) # True print(isinstance(Foo.func,MethodType)) # False
注意:
方法,無需傳入self參數
函數,必須手動傳入self參數
轉載于:https://www.cnblogs.com/wangbaihan/p/8052677.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: MySQL-常用命令大全
- 下一篇: js比较查看两个数组之间是否相等