Jan-08-2019, 11:03 AM
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:
Cheers
Edit: 'myfunc' should be 'foo'. Unfortunately I am not allowed to edit my post to correct this (???)
def foo(n): return lambda a : a * n bar = myfunc(3) print(bar(11))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:
def foo(n,m): return lambda a : a * (n+m) bar = myfunc(3) print(bar(11,5))What is the cause of this issue, and how should I resolve it?
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:
def foo(n): return lambda a : a * n bar = myfunc(3) print(bar(11))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:
def foo(n,m): return lambda a : a * (n+m) bar = myfunc(3) print(bar(11,5))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 (???)