Function definition: Difference between revisions

Content added Content deleted
(Python)
(callable)
Line 39: Line 39:
Unnamed function:
Unnamed function:
multiply = lambda a, b: a * b
multiply = lambda a, b: a * b

A callable - may be useful to allow both simple functions and complex classes to use the same interface:
<pre>
>>> class Multiply:
... def __call__(self, a, b):
... return a * b
...
>>> multiply = Multiply()
>>> multiply(3, 4)
12
<pre>


=={{header|Toka}}==
=={{header|Toka}}==