When might you use a lamda expression instead of a def?
Answer
When a simple function is needed as an argument or return value.
Tags
#python #sicp
Question
When might you use a lamda expression instead of a def?
Answer
?
Tags
#python #sicp
Question
When might you use a lamda expression instead of a def?
Answer
When a simple function is needed as an argument or return value.
If you want to change selection, open original toplevel document below and click on "Move attachment"
Parent (intermediate) annotation
Open it In general, Python style prefers explicit def statements to lambda
expressions, but allows them in cases where a simple function is needed as an
argument or return value.
Original toplevel document
1.6 Higher-Order Functions ver, compound lambda expressions are
notoriously illegible, despite their brevity. The following definition is
correct, but many programmers have trouble understanding it quickly.
>>> compose1 = lambda f,g: lambda x: f(g(x))
<span>In general, Python style prefers explicit def statements to lambda
expressions, but allows them in cases where a simple function is needed as an
argument or return value.
Such stylistic rules are merely guidelines; you can program any way you wish.
However, as you write programs, think about the audience of people who might
read your program one day.
Summary
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Details
No repetitions
Discussion
Do you want to join discussion? Click here to log in or create user.