What does cls() function do inside a class method?

前端 未结 3 1815
一生所求
一生所求 2021-02-01 22:26

Today I\'m viewing another\'s code, and saw this:

class A(B): 
    # Omitted bulk of irrelevant code in the class

    def __init__(self, uid=None):
        self         


        
3条回答
  •  情深已故
    2021-02-01 23:15

    cls is the constructor function, it will construct class A and call the __init__(self, uid=None) function.

    If you enherit it (with C), the cls will hold 'C', (and not A), see AKX answer.

提交回复
热议问题