Extract values from a def()

Q1. How can I extract values from a def() function? Specifically, in these instances, either a or b values.

def absoluteA (a):
    a = abs(a)
    b = -a 
    return (b,a)
print(absoluteA(4))

def absoluteB (a):
    a = abs(a)
    b = -abs(a)
    return (b,a)
print(absoluteB(5))
# result
(-4, 4)
(-5, 5)

Q2: How do I multiply two set of numbers?
First def() + 2nd def() doesn’t work. Thus, returning to the 1st question.

I searched Google but was unable to obtain the solution I desired.

Thanks!

There are a few ways to do this. Possibly, the most straightforward would be to assign the returned values to two variables.

As an example:

def absoluteA(a):
    a = abs(a)
    b = -a
    return (b, a)

b, a = absoluteA(4)

… the names of which can be whatever you like (within reason). I’ve used b and a for the sake of clarity.

1 Like