0
Challenge question...
Having trouble figuring out what is going on here: https://code.sololearn.com/cUiml89ghOmd/?ref=app My first confusion is passing 2 to function x, but x is defined as x(a=0). What does the value 2 get assigned? My second confusion is x()(3). Where do these values go? Thank you for any help.
3 Answers
+ 1
yes it's calling a=2. because that's what is passed. otherwise it would be a=0.
the code has two functions one inside another (nested) . outer and inner function.
when you do x() (3). it's like a short way of calling y(3).
you could do :
result = x()
print(x(2) + result (3))
and get the same output 7
x() returns a functioncallable object.
0
the first case x(2):
x is not defined as x(a=0), rather it's the default value for the function if no value is passed to it. since 2 is passed 0 is ignored.
when you define a function you can specify a default value to be used in case a user did not enter anything.
the second case x() (3) : it is calling the inner function.
0
Letâs see if I am following your explanation. The first case a=2 not a=0.
I do not follow what you mean by calling the inner function.