@@ -955,11 +955,16 @@ \section{Boolean operations\label{Booleans}}
955955same type as its argument, so e.g., \code {not 'foo' } yields \code {0},
956956not \code {''}.)
957957
958+ \section {Lambdas\label {lambdas } }
959+ \indexii {lambda}{expression}
960+ \indexii {lambda}{form}
961+ \indexii {anonmymous}{function}
962+
958963Lambda forms (lambda expressions) have the same syntactic position as
959964expressions. They are a shorthand to create anonymous functions; the
960965expression \code {lambda \var {arguments}: \var {expression}}
961- yields a function object that behaves virtually identical to one
962- defined with
966+ yields a function object. The unnamed object behaves like a function
967+ object define with
963968
964969\begin {verbatim }
965970def name(arguments):
@@ -969,34 +974,6 @@ \section{Boolean operations\label{Booleans}}
969974See section \ref {function } for the syntax of parameter lists. Note
970975that functions created with lambda forms cannot contain statements.
971976\label {lambda }
972- \indexii {lambda}{expression}
973- \indexii {lambda}{form}
974- \indexii {anonmymous}{function}
975-
976- \strong {Programmer's note:} Prior to Python 2.1, a lambda form defined
977- inside a function has no access to names defined in the function's
978- namespace. This is because Python had only two scopes: local and
979- global. A common work-around was to use default argument values to
980- pass selected variables into the lambda's namespace, e.g.:
981-
982- \begin {verbatim }
983- def make_incrementor(increment):
984- return lambda x, n=increment: x+n
985- \end {verbatim }
986-
987- As of Python 2.1, nested scopes were introduced, and this work-around
988- has not been necessary. Python 2.1 supports nested scopes in modules
989- which include the statement \samp {from __future__ import
990- nested_scopes}, and more recent versions of Python enable nested
991- scopes by default. This version works starting with Python 2.1:
992-
993- \begin {verbatim }
994- from __future__ import nested_scopes
995-
996- def make_incrementor(increment):
997- return lambda x: x+increment
998- \end {verbatim }
999-
1000977
1001978\section {Expression lists\label {exprlists } }
1002979\indexii {expression}{list}
0 commit comments