I have a class with several methods. One method creates an empty list, another method appends one item to that list and there is another which uses the first one to create a list and then the 2nd one for appending numbers through a loop, so that in the end, the empty list will become a populated list.
This is my code:
class CV:
def create_metrics(self):
self.a_list = []
def add(self):
self.a_list=self.a_list.append(self.number)
def bucle(self):
self.create_metrics()
for i in range(3):
self.number = 3*i
self.add()
a = CV()
a.bucle()
However, I am getting the error 'NoneType' object has no attribute 'append'
. If I run
a = CV()
a.create_metrics()
a.a_list
It can be checked that effectively, the list has been created and is empty, so I have no idea why when I run the complete code it is created a NoneType object.
The desired output would be a_list = [0,3,6]