Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9164
| Date | 2011-07-10 07:21 -0700 |
|---|---|
| From | Yingjie Lan <lanyjie@yahoo.com> |
| Subject | anonymous function with multiple statements |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.837.1310307904.1164.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
anonymous function with multiple statements Yingjie Lan <lanyjie@yahoo.com> - 2011-07-10 07:21 -0700
csiph-web