开发者

How different types of methods work in Python (OOP) [duplicate]

This question already has answers here: Meaning of @classmethod and @staticmethod for beginner [duplicate] (12 answers) Can we create instance method with out self (3 answers) Class method differences in Python: bound, unbound and static (13 answers) Closed 1 hour ago.
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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜