-2

I'm trying to activate a function which is stored inside a variable. I've tried to use "lambda:" like this:

def test():
    print("this works")

var = test()
lambda: var

It doesn't work. Is there any way to do that without doing anything complex? If not I don't mind hearing the complex way.


Edit:

When I posted this I meant that I wanted parameters in the function for example if you use:

def test(thing):
    print(thing)

var = test
var()

Sorry for the confusion.

SollyBunny
  • 800
  • 1
  • 8
  • 15

1 Answers1

4

You use the parentheses to call the function. When you assign, you don't need the parentheses.

>>> def test():
...     print("this works")
...
>>> var = test
>>> var()
this works
richflow
  • 1,902
  • 3
  • 14
  • 21