Python Forum

Full Version: python question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello! I am a beginner and I need help. What's the problem with this syntex? Thanks for the help

class Alma

    def __init__(x):

        self.x = x

    def count(self,x):

        self.x = x+1

class ZoldAlma:

    def __init__(self, y=0):

        Alma.__init__(self, 3)

        self.y = y

    def count(self):

        self.y += 1     

def main():

    obj = ZoldAlma()

    obj.count()

    print(obj.x, obj.y)

main()
In Alma __init__ needs self as the first argument
In ZoldAlma the call to Alma should be self.somevar = Alma(3)
ZoldAlma does not have x. If you changed the code as above, then obj.somevar.x can be referenced and printed.