__init__ and arguments in Python

前端 未结 6 1350
我寻月下人不归
我寻月下人不归 2021-01-31 14:53

I want to understand arguments of the constructor __init__ in Python.

class Num:
    def __init__(self,num):
        self.n = num
    def getn(self)         


        
6条回答
  •  一个人的身影
    2021-01-31 15:33

    The fact that your method does not use the self argument (which is a reference to the instance that the method is attached to) doesn't mean you can leave it out. It always has to be there, because Python is always going to try to pass it in.

提交回复
热议问题