TypeError: Missing 1 required positional argument: 'self'

后端 未结 6 844
借酒劲吻你
借酒劲吻你 2020-11-22 02:18

I am new to python and have hit a wall. I followed several tutorials but cant get past the error:

Traceback (most recent call last):
  File \"C:\\Users\\Dom\         


        
6条回答
  •  时光说笑
    2020-11-22 02:59

    The self keyword in Python is analogous to this keyword in C++ / Java / C#.

    In Python 2 it is done implicitly by the compiler (yes Python does compilation internally). It's just that in Python 3 you need to mention it explicitly in the constructor and member functions. example:

     class Pump():
     //member variable
     account_holder
     balance_amount
    
       // constructor
       def __init__(self,ah,bal):
       |    self.account_holder = ah
       |    self.balance_amount = bal
    
       def getPumps(self):
       |    print("The details of your account are:"+self.account_number + self.balance_amount)
    
     //object = class(*passing values to constructor*)
     p = Pump("Tahir",12000)
     p.getPumps()
    

提交回复
热议问题