Just started learning programming a few weeks ago. Tried running the following python code but it returned an error : TypeError: altered() missing 1 required positional argument: 'self'.
But if I declare the classes as variables it worked out nicely, like so:
Would appreciate some explanation why this is the case.
Thanks
Credits to Learn Python 3 the Hard Way by Zed Shaw for the code.
Code:
class Parent(object):
def altered (self):
print("Parent altered")
class Child(Parent):
def altered(self):
print("Child, before parent altered")
super(Child,self).altered()
print("Child, after parent altered")
Parent.altered()
Child.altered()
But if I declare the classes as variables it worked out nicely, like so:
Code:
class Parent(object):
def altered (self):
print("Parent altered")
class Child(Parent):
def altered(self):
print("Child, before parent altered")
super(Child,self).altered()
print("Child, after parent altered")
a = Parent()
b = Child()
a.altered()
b.altered()
Would appreciate some explanation why this is the case.
Thanks
Credits to Learn Python 3 the Hard Way by Zed Shaw for the code.