How different types of methods work in Python (OOP) [duplicate]
class Test:
def normal_method(name):
print(f'Method called: , {name}')
def instance_method(self, name):
print(f'Method called: , {name}')
@classmethod
def class_method(cls, name):
print(f'Method called: , {name}')
@staticmethod
def static_method(name):
print(f'Method called: , {name}')
if __name__ == '__main__':
Test.normal_method('normal_method')
Test().instance_method('instance_method')
Test.class_method('class_method')
Test.static_method('static_method')
Can anyone please tell me here what is the difference between normal_method
, instance_method
and class_method
?
My main question is about the internal working in normal_method
开发者_如何学JAVA, instance_method
and class_method
. Where the obj of the class will be created and where not? Please reply with sufficient and accurate answer. I have already gone through many documentation but didn't find sufficient notes.
精彩评论