Study Notes (06): Python Interview 100 talking about (based Python3.x) - judgment call is a function or method

Learning immediately: https://edu.csdn.net/course/play/26755/340162?utm_source=blogtoedu

1 is a function or method to determine how to call

 

 

Isinstance function can judge by calling a function or method.

 

Function type is FunctionType

 

The method is MethodType

class MyClass:
    def process(self):
        pass

def process():
    pass

print(type(MyClass().process).__name__ == 'method')
print(type(process).__name__ == 'function')

from types import MethodType,FunctionType

print('MyClass.process:',isinstance(MyClass().process,FunctionType))
print('MyClass.process:',isinstance(MyClass().process,MethodType))
print('process:',isinstance(MyClass().process,FunctionType))
print('process:',isinstance(MyClass().process,MethodType))

 

Released seven original articles · won praise 1 · views 97

Guess you like

Origin blog.csdn.net/qq_44980274/article/details/104391927