I am trying to understand python classes:
I have the following case:
class parent:
def __init__(self):
self.a = 1
self.b = 2
def printFoo(self):
print(self.a)
class child(parent):
def createC(self, val): # Create a variable inside the derived class?
self.c = val
def printFoo(self): # overloaded function
print(self.c)
a = parent()
b = child()
b.createC(3)
b.printFoo()
# Edited:
# I can even create variables as: child.d = 10
I would like to define a variable c
and store it in the child
class. Is it suitable to do this? Should I define an __init__
method to create the variable?
Best regards