3

I have a Python function that returns a set of values say a1,...,an.

Example. The returned set is a1,a2,a3,a4.

def myFunction():
    # The code
    return a1,a2,a3,a4 

I would like to access only a1 and a4 for example, how?

I tried

a1, , ,a4 = myFunction()

but it gives me error too many to unpack

EDIT The error too many to unpackwas only given when I tried a1,=myFunction()

Ribz
  • 551
  • 1
  • 4
  • 13

1 Answers1

3

Use

a1, _, _,a4 = myFunction()

using _ is a common convention in Python for variables that are likely not to be used; they are still variables though.

Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67