Guys, help me figure out how to pass a list of arguments to the class constructor and loop through this list?

class A(): def __init__(self,*name): self.name = name def func(self): if self.name == 'a': print ('aaa') elif self.name == 'b': print ('bbb') elif self.name == 'c': print ('ccc') 

By tyke method I realized that it is possible to pass arguments there, in fact, through a cycle:

 letters = ['a','b','c'] for i in letters: letters = A(i) letters.func() 

But somehow it seems to me cumbersome. Maybe there is a more "correct" way?

    1 answer 1

    Not very clear what you want. Maybe this:

     class A: def __init__(self, *names): self.names = names def func(self): for n in self.names: if n == 'a': print('aaa') elif n == 'b': print('bbb') elif n == 'c': print('ccc') a = A('a', 'b', 'c') a.func() 
    • It was required. Blunted)) - moffire