Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > anonymous function with multiple statements

Thread Tools

anonymous function with multiple statements

Yingjie Lan
Posts: n/a
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?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
if statements and case statements questions John Crichton Ruby 6 07-12-2010 06:17 PM
Prepare Statements VS Statements Vince Java 12 01-21-2008 01:18 PM
Is this a local anonymous class or a member anonymous class Reporter Java 3 05-12-2007 05:23 AM
component statements within architecture statements Neil Zanella VHDL 8 10-20-2006 09:05 AM
if statements with or w/o else statements Harry George Python 6 02-23-2004 06:48 PM