Page 1 of 1

Python Argument Passing

Posted: Mon Apr 19, 2004 7:03 pm
by Kyouryuu
Is it possible in the Python language to pass a function as an argument? Like, for example, if I wanted to have the following:

a = Item("Elixir", "It restores your health", hp += 5)

And, if so, what would that look like?

Posted: Mon Apr 19, 2004 7:46 pm
by DCrazy
What you want to do can be done with Lambda functions. Link: http://www.secnetix.de/~olli/Python/lam ... tions.hawk

Example:

Code: Select all

a = Item("Elixir", "It restores your health", lambda: hp+=5)

Posted: Mon Apr 19, 2004 9:11 pm
by Kyouryuu
Thanks, DCrazy. :D