[Tutor] Unpack from list
Sunil Tech
sunil.techspk at gmail.com
Mon Jul 13 14:03:03 CEST 2015
Hi Tutor,
[a,b,c] = [1,2]
this will give
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 2 values to unpack
But is there any chance, if there are 3 values on left hand side and 2
values on right side, to add an empty value to the left side dynamically?
there can be multiple elements to unpack depending on what is expected on
left side.
Like in methods there can be optional parameters, if the values is not
passed, optional values will take what is been declared.
def optal(a,b,c=''):
"""
c - is option
"""
Thanks,
Sunil. G
More information about the Tutor
mailing list