mirror of https://github.com/python/cpython
a few updates to the gloassary with regards to __future__ and division
This commit is contained in:
parent
58425d3103
commit
2d71822fdb
|
@ -74,10 +74,7 @@ Glossary
|
||||||
``int(3.15)`` converts the floating point number to the integer ``3``, but
|
``int(3.15)`` converts the floating point number to the integer ``3``, but
|
||||||
in ``3+4.5``, each argument is of a different type (one int, one float),
|
in ``3+4.5``, each argument is of a different type (one int, one float),
|
||||||
and both must be converted to the same type before they can be added or it
|
and both must be converted to the same type before they can be added or it
|
||||||
will raise a ``TypeError``. Coercion between two operands can be
|
will raise a ``TypeError``. Without coercion, all arguments of even
|
||||||
performed with the ``coerce`` builtin function; thus, ``3+4.5`` is
|
|
||||||
equivalent to calling ``operator.add(*coerce(3, 4.5))`` and results in
|
|
||||||
``operator.add(3.0, 4.5)``. Without coercion, all arguments of even
|
|
||||||
compatible types would have to be normalized to the same value by the
|
compatible types would have to be normalized to the same value by the
|
||||||
programmer, e.g., ``float(3)+4.5`` rather than just ``3+4.5``.
|
programmer, e.g., ``float(3)+4.5`` rather than just ``3+4.5``.
|
||||||
|
|
||||||
|
@ -180,6 +177,11 @@ Glossary
|
||||||
A module written in C or C++, using Python's C API to interact with the core and
|
A module written in C or C++, using Python's C API to interact with the core and
|
||||||
with user code.
|
with user code.
|
||||||
|
|
||||||
|
floor division
|
||||||
|
Mathematical division discarding any remainder. The floor division
|
||||||
|
operator is ``//``. For example, the expression ``11//4`` evaluates to
|
||||||
|
``2`` in contrast to the ``2.75`` returned by float true division.
|
||||||
|
|
||||||
function
|
function
|
||||||
A series of statements which returns some value to a caller. It can also
|
A series of statements which returns some value to a caller. It can also
|
||||||
be passed zero or more arguments which may be used in the execution of
|
be passed zero or more arguments which may be used in the execution of
|
||||||
|
@ -187,16 +189,11 @@ Glossary
|
||||||
|
|
||||||
__future__
|
__future__
|
||||||
A pseudo module which programmers can use to enable new language features
|
A pseudo module which programmers can use to enable new language features
|
||||||
which are not compatible with the current interpreter. For example, the
|
which are not compatible with the current interpreter.
|
||||||
expression ``11/4`` currently evaluates to ``2``. If the module in which
|
|
||||||
it is executed had enabled *true division* by executing::
|
|
||||||
|
|
||||||
from __future__ import division
|
By importing the :mod:`__future__` module and evaluating its variables,
|
||||||
|
you can see when a new feature was first added to the language and when it
|
||||||
the expression ``11/4`` would evaluate to ``2.75``. By importing the
|
becomes the default::
|
||||||
:mod:`__future__` module and evaluating its variables, you can see when a
|
|
||||||
new feature was first added to the language and when it will become the
|
|
||||||
default::
|
|
||||||
|
|
||||||
>>> import __future__
|
>>> import __future__
|
||||||
>>> __future__.division
|
>>> __future__.division
|
||||||
|
@ -271,18 +268,6 @@ Glossary
|
||||||
role in places where a constant hash value is needed, for example as a key
|
role in places where a constant hash value is needed, for example as a key
|
||||||
in a dictionary.
|
in a dictionary.
|
||||||
|
|
||||||
integer division
|
|
||||||
Mathematical division discarding any remainder. For example, the
|
|
||||||
expression ``11/4`` currently evaluates to ``2`` in contrast to the
|
|
||||||
``2.75`` returned by float division. Also called *floor division*. When
|
|
||||||
dividing two integers the outcome will always be another integer (having
|
|
||||||
the floor function applied to it). However, if the operands types are
|
|
||||||
different, one of them will be converted to the other's type. For
|
|
||||||
example, an integer divided by a float will result in a float value,
|
|
||||||
possibly with a decimal fraction. Integer division can be forced by using
|
|
||||||
the ``//`` operator instead of the ``/`` operator. See also
|
|
||||||
:term:`__future__`.
|
|
||||||
|
|
||||||
interactive
|
interactive
|
||||||
Python has an interactive interpreter which means you can enter
|
Python has an interactive interpreter which means you can enter
|
||||||
statements and expressions at the interpreter prompt, immediately
|
statements and expressions at the interpreter prompt, immediately
|
||||||
|
|
Loading…
Reference in New Issue