Ask Your Question
0

I am a total newbie (and don't apologize for it!) What does the operator "lambda" do? What does it mean?

asked 2014-12-13 22:04:11 -0500

cltho2 gravatar image

I am a total newbie (and don't apologize for it!) What does the operator "lambda" do? What does it mean?

edit retag flag offensive close merge delete

Comments

You should shorten your title to ease readability of asksage (as such it looks like spam).

tmonteil gravatar imagetmonteil ( 2014-12-13 23:18:16 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2014-12-13 22:58:39 -0500

tmonteil gravatar image

Short answer : lambda is used to create short and anonymous Python functions. For example, instead of writing:

sage: def inc(n):
....:     return n+1

You can write:

 sage: inc = lambda x : x+1

but lambda x : x+1 can be used directly in your code, without needing to name it inc, while the def construction require to give a name and use return

Longer answer : http://www.sagemath.org/doc/thematic_...

edit flag offensive delete link more
0

answered 2014-12-15 09:52:44 -0500

kcrisman gravatar image

To answer an implicit question of why you might use them, sometimes there are functions you want to do something with in Sage that are not symbolic - see e.g. this documentation or here.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-12-13 22:04:11 -0500

Seen: 222 times

Last updated: Dec 15 '14