I was trying to create multiple data members for a class in python uisng the for loop but seems like python creates just a single data member for each loop iteration. I am sure the way am doing it is correct or not but if any of you get my motive and can help then please do. I think setitem
could be a solution but i don't know how?
class VectorNd:
def __init__(self,**kwargs):
self.length = 0
self.member_names = kwargs.keys()
for (i,j) in kwargs.items():
self.i = j
def __str__(self):
ret_str = ''
print(self.member_names)
for i in self.member_names:
ret_str += f'({self.i}{i}) +'
return ret_str[:-2]
obj = VectorNd(i=1,j=2,k=3,l=5)
print(obj.i)
Output:
5
I wish to create new data members each time the loop is iterated instead of creating a single self.i
data member.