function code snippet that has function calls I have never seen before. How does it work.

Denis McMahon denismfmcmahon at gmail.com
Sat Oct 3 15:59:07 EDT 2015


On Sat, 03 Oct 2015 10:40:57 -0700, Ronald Cosentino wrote:

> def funA(x,y,z):
>     return (x+y) * z
> def funB(x,y):
>     return(x-y)
> print(funA(4,funB(2,3), funB(3,2)))
> 
> the answer is 3. I don't know how it works.

def funA(x, y, z):
    return (x+y) * z

def funB(x, y):
    return (x-y)

# this line
# print(funA(4,funB(2,3), funB(3,2)))
# can be written as the following 4 lines:

a = funB(2, 3) # 2 - 3 -> -1

b = funB(3, 2) # 3 - 2 -> 1

c = funA(4, a, b) # (4 + -1) * 1 -> 3

print(c) # 3

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list