[Python-checkins] cpython (merge 3.3 -> default): merge with 3.3
georg.brandl
python-checkins at python.org
Sun Oct 6 10:22:27 CEST 2013
http://hg.python.org/cpython/rev/ab7b5ba360e9
changeset: 86023:ab7b5ba360e9
parent: 86019:ff09a02ce029
parent: 86022:ef1a17d5e263
user: Georg Brandl <georg at python.org>
date: Sun Oct 06 10:22:54 2013 +0200
summary:
merge with 3.3
files:
Doc/tutorial/controlflow.rst | 27 +++++++++++++++--------
1 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -583,17 +583,16 @@
.. _tut-lambda:
-Lambda Forms
-------------
+Lambda Expressions
+------------------
-By popular demand, a few features commonly found in functional programming
-languages like Lisp have been added to Python. With the :keyword:`lambda`
-keyword, small anonymous functions can be created. Here's a function that
-returns the sum of its two arguments: ``lambda a, b: a+b``. Lambda forms can be
-used wherever function objects are required. They are syntactically restricted
-to a single expression. Semantically, they are just syntactic sugar for a
-normal function definition. Like nested function definitions, lambda forms can
-reference variables from the containing scope::
+Small anonymous functions can be created with the :keyword:`lambda` keyword.
+This function returns the sum of its two arguments: ``lambda a, b: a+b``.
+Lambda forms can be used wherever function objects are required. They are
+syntactically restricted to a single expression. Semantically, they are just
+syntactic sugar for a normal function definition. Like nested function
+definitions, lambda functions can reference variables from the containing
+scope::
>>> def make_incrementor(n):
... return lambda x: x + n
@@ -604,6 +603,14 @@
>>> f(1)
43
+The above example uses a lambda expression to return a function. Another use
+is to pass a small function as an argument::
+
+ >>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
+ >>> pairs.sort(key=lambda pair: pair[1])
+ >>> pairs
+ [(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]
+
.. _tut-docstrings:
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list