I have very recently started looking at python, most of my (recent) prior programming experience being with VBA, and have been following the W3Schools tutorials. I am currently looking at Lambda functions (specifically here: https://www.w3schools.com/python/python_lambda.asp) and am struggling to implement them into my code. The following code works fine:
However, the issues I come into arise when using a lambda function which uses a different number of arguments to the function that it is used within. For example, I cannot get the following code to work:
What is the cause of this issue, and how should I resolve it?
Cheers
Edit: 'myfunc' should be 'foo'. Unfortunately I am not allowed to edit my post to correct this (???)
1 2 3 4 5 6 |
def foo(n): return lambda a : a * n bar = myfunc( 3 ) print (bar( 11 )) |
1 2 3 4 5 6 |
def foo(n,m): return lambda a : a * (n + m) bar = myfunc( 3 ) print (bar( 11 , 5 )) |
Cheers

(Jan-08-2019, 11:03 AM)JChapman Wrote: I have very recently started looking at python, most of my (recent) prior programming experience being with VBA, and have been following the W3Schools tutorials. I am currently looking at Lambda functions (specifically here: https://www.w3schools.com/python/python_lambda.asp) and am struggling to implement them into my code. The following code works fine:
However, the issues I come into arise when using a lambda function which uses a different number of arguments to the function that it is used within. For example, I cannot get the following code to work:
123456def
foo(n):
return
lambda
a : a
*
n
bar
=
myfunc(
3
)
(bar(
11
))
What is the cause of this issue, and how should I resolve it?
123456def
foo(n,m):
return
lambda
a : a
*
(n
+
m)
bar
=
myfunc(
3
)
(bar(
11
,
5
))
Cheers
Edit: 'myfunc' should be 'foo'. Unfortunately I am not allowed to edit my post to correct this (???)