The Python Library Reference, Release 3.2.1
a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs).
1
If it is a code object, it is simply executed. In all cases, the code that’s executed is expected to be valid as file
input (see the section “File input” in the Reference Manual). Be aware that the return and yield statements
may not be used outside of function definitions even within the context of code passed to the exec() function.
The return value is None.
In all cases, if the optional parts are omitted, the code is executed in the current scope. If only globals is
provided, it must be a dictionary, which will be used for both the global and the local variables. If globals and
locals are given, they are used for the global and local variables, respectively. If provided, locals can be any
mapping object.
If the globals dictionary does not contain a value for the key __builtins__, a reference to the dictionary of
the built-in module builtins is inserted under that key. That way you can control what builtins are available to
the executed code by inserting your own __builtins__ dictionary into globals before passing it to exec().
Note: The built-in functions globals() and locals() return the current global and local dictionary,
respectively, which may be useful to pass around for use as the second and third argument to exec().
Note: The default locals act as described for function locals() below: modifications to the default locals
dictionary should not be attempted. Pass an explicit locals dictionary if you need to see effects of the code on
locals after function exec() returns.
filter(function, iterable)
Construct an iterator from those elements of iterable for which function returns true. iterable may be either
a sequence, a container which supports iteration, or an iterator. If function is None, the identity function is
assumed, that is, all elements of iterable that are false are removed.
Note that filter(function, iterable) is equivalent to the generator expression (item for
item in iterable if function(item)) if function is not None and (item for item in
iterable if item) if function is None.
See itertools.filterfalse() for the complementary function that returns elements of iterable for
which function returns false.
float([x ])
Convert a string or a number to floating point.
If the argument is a string, it should contain a decimal number, optionally preceded by a sign, and optionally
embedded in whitespace. The optional sign may be ’+’ or ’-’; a ’+’ sign has no effect on the value produced.
The argument may also be a string representing a NaN (not-a-number), or a positive or negative infinity. More
precisely, the input must conform to the following grammar after leading and trailing whitespace characters are
removed:
sign ::= “+” | “-“
infinity ::= “Infinity” | “inf”
nan ::= “nan”
numeric_value ::= floatnumber | infinity | nan
numeric_string ::= [sign] numeric_value
Here floatnumber is the form of a Python floating-point literal, described in floating. Case is not significant,
so, for example, “inf”, “Inf”, “INFINITY” and “iNfINity” are all acceptable spellings for positive infinity.
Otherwise, if the argument is an integer or a floating point number, a floating point number with the same value
(within Python’s floating point precision) is returned. If the argument is outside the range of a Python float, an
1
Note that the parser only accepts the Unix-style end of line convention. If you are reading the code from a file, make sure to use newline
conversion mode to convert Windows or Mac-style newlines.
10 Chapter 2. Built-in Functions