function code snippet that has function calls I have never seen before. How does it work.
Ervin Hegedüs
airween at gmail.com
Sat Oct 3 14:09:43 EDT 2015
hi,
On Sat, Oct 03, 2015 at 10:40:57AM -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.
it's simple:
- there is a "composition of functions", generally
f(g()) (function in argument list of another function)
- first, Python evaulates the arguments first, from left to right
- in this point, you'll get -1 for 2nd arg, and 1 for 3rd arg
- then your funcA() will be called with these arguents:
4, -1, 1
- funcA() calculates this:
(x+y)*z, in this case (4+(-1))*1
which is 3...
a.
--
I � UTF-8
More information about the Python-list
mailing list