+ 2
How to call this function?
9 Answers
+ 4
I think you just want to output the sum of two variables. You do not need to define h inside g for this. Just try this.
g(x,y):
return x+y
#to see an output type the below line of code
print(g(2,3))
+ 3
Then you must know that a function can only be called inside its' scope.
So your code should be modified like this:
def g(x):
def h(y):
return x+y
return h(5) #the "y"
print(g(6))
+ 3
Cause there's no such syntax in Python...
+ 3
# You could do something like this and call funny()()
def funny(a):
return lambda b, a=a: a+b
print(funny(3)(4))
+ 3
Norberto Costa
def g(x,y):
def h(y):
return y*2
return x + h(y)
print(g(6,7)) #20
Access to h(y) is gained through g(y).
g() then calls the result of h() and creates a new result when g() is called
+ 1
Norberto Costa
I don't think you can call the function h() or assign h() a value because g() does not allow access to it
0
So how to modify it?
0
No. I want to work with nested functions.
0
Why can't call g(6)(5)