-1

This a simply code that I trying to access to a method in a class from another method in the same class but it is given me that error any help?

class menu:
    def __init__(self,a,b):
        self.a=a
        self.b=b

    def suma(self):
        x=self.a+self.b
        print(x)

    def hola(): 
        menu.suma()


menu=menu(1,2)
menu.hola()

1 Answers1

0

How to avoid explicit 'self' in Python?

You need an explicit self in python. The self argument is always passed in.

class menu:
    def __init__(self,a,b):
        self.a=a
        self.b=b

    def suma(self):
        x=self.a+self.b
        print(x)

    def hola(self): 
        menu.suma()


menu=menu(1,2)
menu.hola()
jshamble
  • 391
  • 2
  • 14