Using super with a class method

后端 未结 5 516
囚心锁ツ
囚心锁ツ 2020-12-13 05:48

I\'m trying to learn the super() function in Python.

I thought I had a grasp of it until I came over this example (2.6) and found myself stuck.

http://www.ca

5条回答
  •  借酒劲吻你
    2020-12-13 06:08

    I've updated the article to make it a bit clearer: Python Attributes and Methods # Super

    Your example using classmethod above shows what a class method is - it passes the class itself instead of the instance as the first parameter. But you don't even need an instance to call the method, for e.g.:

    >>> class A(object):
    ...     @classmethod
    ...     def foo(cls):
    ...         print cls
    ... 
    >>> A.foo() # note this is called directly on the class
    
    

提交回复
热议问题