Unpack less values from function's return values

Chris Rebert clp2 at rebertia.com
Thu May 28 12:40:12 CEST 2009

On Thu, May 28, 2009 at 3:19 AM,  <dudeja.rajat at gmail.com> wrote:
> Hi,
> I'm using Python 2.5.2. I'm getting this error whenever I try to unpack less
> values from a function.
> ValueError: too many values to unpack
> I want to know if there is a way I can unpack less values returning from a
> function?

Unpack them into throwaway variables:

def foo(): return 1,2,3,4

a, b, _, _ = foo()

In very new Python, you can also do:

a, b, *_ = foo()


More information about the Python-list mailing list