2

I want to pass a function/lambda to a method and then call it in python 2.7:

def foo(f):
    f()

I tried many ways but didnt find the correct syntax. For example this

foo(lambda: print("hallo"))

results in

    foo(lambda: print("hallo"))
                    ^
SyntaxError: invalid syntax

I know that this works:

foo(lambda x: None)

But I dont know how to make the lambda actually do something and at the same time return None

Related: A suitable 'do nothing' lambda expression in python?, though the lambdas in the answer just do nothing :(

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185

0 Answers0