Python Argument Passing

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
Kyouryuu
DBB Alumni
DBB Alumni
Posts: 5775
Joined: Fri Apr 30, 1999 2:01 am
Location: Isla Nublar
Contact:

Python Argument Passing

Post 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?
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post 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)
User avatar
Kyouryuu
DBB Alumni
DBB Alumni
Posts: 5775
Joined: Fri Apr 30, 1999 2:01 am
Location: Isla Nublar
Contact:

Post by Kyouryuu »

Thanks, DCrazy. :D
Post Reply