For example, if I want to assign a, b, c
from l = [1,2,3,4,5]
, I can do
a, b, c = l[:3]
but what if l
is only [1,2]
(or [1]
or []
) ?
Is there a way to automatically set the rest of the variables to None
or ''
or 0
or some other default value?
I thought about extending the list with default values before assigning to match the number of variables, but just wondering if there's a better way.