I am new to python and created the below code to undersstand some conocepts of inheritance. however, the method print(x.showBaseListContents()) should display only the contents of the list but as shown below in the output i received NONE. please let me know when i received NONE
derived class
#from BaseClass import BaseClass
from BaseClass import BaseClass
class DerivedClass(BaseClass):
def __init__(self, val1,val2, val3):
BaseClass.__init__(self, val1,val2,val3)
self.__baseList = []
self.__val1 = val1
self.__val2 = val2
self.__val3 = val3
x = DerivedClass(10,20,30)
x.addValuesToBaseList()
s = x.getBaseListLength()
print(s)
print(x.showBaseListContents())
Baseclass
class BaseClass:
baseClassAttribute = 10
def __init__(self, val1,val2, val3):
self.__baseList = []
self.__val1 = val1
self.__val2 = val2
self.__val3 = val3
def getVal1(self):
return self.__val1
def getVal2(self):
return self.__val2
def getVal3(self):
return self.__val3
def addValuesToBaseList(self):
self.__baseList.append(self.__val1)
self.__baseList.append(self.__val2)
self.__baseList.append(self.__val3)
def getBaseListLength(self) :
return len(self.__baseList)
def showBaseListContents(self):
for i in self.__baseList:
print(i)
output
3
10
20
30
None