How to unpack optional items from a tuple? [duplicate]
问题 This question already has answers here : Idiomatic way to unpack variable length list of maximum size n (5 answers) How to unpack tuple of length n to m<n variables [duplicate] (5 answers) Closed 6 years ago . I have a list of some input values, of which the first couple of mandatory and the last couple optional. Is there any easy way to use tuple unpacking to assign these to variables, getting None if the optional parameters are missing. eg. a = [1,2] foo, bar, baz = a # baz == None ideally