Class method differences in Python: bound, unbound and static

后端 未结 13 1229
日久生厌
日久生厌 2020-11-22 08:54

What is the difference between the following class methods?

Is it that one is static and the other is not?

class Test(object):
  def method_one(self)         


        
13条回答
  •  独厮守ぢ
    2020-11-22 09:26

    that is an error.

    first of all, first line should be like this (be careful of capitals)

    class Test(object):
    

    Whenever you call a method of a class, it gets itself as the first argument (hence the name self) and method_two gives this error

    >>> a.method_two()
    Traceback (most recent call last):
    File "", line 1, in 
    TypeError: method_two() takes no arguments (1 given)
    

提交回复
热议问题