Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9164 > unrolled thread
| Started by | Yingjie Lan <lanyjie@yahoo.com> |
|---|---|
| First post | 2011-07-10 07:21 -0700 |
| Last post | 2011-07-10 07:21 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
anonymous function with multiple statements Yingjie Lan <lanyjie@yahoo.com> - 2011-07-10 07:21 -0700
| From | Yingjie Lan <lanyjie@yahoo.com> |
|---|---|
| Date | 2011-07-10 07:21 -0700 |
| Subject | anonymous function with multiple statements |
| Message-ID | <mailman.837.1310307904.1164.python-list@python.org> |
Hi all,
I wonder if Python provides a way to define anonymous functions containing
multiple statements? With lambda form, we can only define a function of a single
expression. In Javascript, it is possible to define
a full-fledged anonymous functions, which suggests it is useful to have it. In
Python, it might be like this:
#==============
def test( fn, K ):
return sum(fn(i) for i in range(K))/K
test( def (i): #indent from start of this line, not from 'def'
from math import sin
#the last statement ends with a ',' or ')'.
return sin(i)+i*i;, 100) #';' to mark end of statement
#another way:
test( def (i): #indent from start of this line, not from 'def'
from math import sin
return sin(i)+i*i
, 100) #freely place ',' anywhere
#===============
Any thoughts?
Yingjie
Back to top | Article view | comp.lang.python
csiph-web