[Solved] Why the method in some class I created, ask me for input “self”? [closed]


You have to create an object of your class:

class MyClass:
  def __init__(self,a=1,b=2):
      self.a=a
      self.b=b
  def function1(self):
      self.c=self.a/self.b + 5
      return(self.c)

print(MyClass().function1())

MyClass() creates an object that can be used to access attributes in the class.

For a general instance:

m = MyClass()
print(m.function1())

6

solved Why the method in some class I created, ask me for input “self”? [closed]