class C:
def __init__(self, a,b):
self.a = a
self.b = b
Case 1:
Obj1 = C(1,2)
print Obj1.a
print Obj1.b
Case 2:
l= [1,2]
Obj2 = C(l)
print Obj2.a
print Obj2.b
I want to initialize the object of a class with the list passed as initializer as shown in case 2 but that shows syntax error . Is there any way to do this in python ?
I found out I can use the unpacking here. Thanks for the answer. Can I do some thing like this by combining both of these things I know i just can append one more number and pass it to initialize object but is there a way to combine both these things ?
class C:
def __init__(self, a,b):
self.a = a
self.b = b
self.c = c
l= [1,2]
Obj2 = C(*l,3)