Home > other >  In a class of methods is not a given self why would an error?
In a class of methods is not a given self why would an error?

Time:05-10

 
The class class:
Def method () :
Print (' I have a self! ')
> The instance=Class ()
> The instance method ()
Traceback (the most recent call last) :
The File "& lt; Pyshell# 50 & gt;" , the line 1, the in & lt; module>
The instance method ()
TypeError: method () takes 0 positional arguments but 1 was given


Excuse me, in the class definition, the method is not defined as method (self), why would an error?

I looked at the relevant knowledge, the instance is a Class instance of the Class, the instance. The method () call in the Class method is to use the instance, equivalent to the Class. The method (), but the method with the code without involving the self related attributes, such as the self. The name, why still need to write it method method (self), I am not very understand, thank you bosses give to solve!
  • Related