-2

I have defined a function as:

def f():
    a = 5
    b = 6
    c = 7

    def g(x): 
         return x+2

    return a, b , c, g

I would like to know how to get only one of the value returned, without the other ones. For example If I am only interested in c, is there an alternative to:

a, b, c, g = f()

To get c?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Sarah
  • 37
  • 4

1 Answers1

2

Python returns multiple values as a tuple. You can check this by doing

>>> type(f())
>>> <class 'tuple'>

As from your implementation we can assume that the c variable value always lies on the index 2 so you can do

c_value = f()[2]
Dsujan
  • 411
  • 3
  • 14