>>
>
..
.
.pyc
and .pyo
files so that executing the same file is faster the second time
(compilation from source to byte code can be saved). This
``intermediate language'' is said to run on a ``virtual
machine'' that calls the subroutines corresponding to each bytecode.
int(3.15)
coerces the floating point number to the integer,
3
. Most mathematical operations have rules for coercing
their arguments to a common type. For instance, adding 3+4.5
,
causes the integer 3
to be coerced to be a float
3.0
before adding to 4.5
resulting in the float
7.5
.
11/4
currently evaluates to 2
.
If the module in which it is executed had enabled true division
by executing:
from __future__ import division
the expression 11/4
would evaluate to 2.75
. By actually
importing the __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__ >>> __future__.division _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
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 one of the operands is another numeric type (such as a
float), the result will be coerced (see coercion) to
a common type. For example, a 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 __future__.
python
with no
arguments (possibly by selecting it from your computer's main menu).
It is a very powerful way to test out new ideas or inspect modules and
packages (remember help(x)
).
for
statement does
that automatically for you, creating a temporary unnamed variable to
hold the iterator for the duration of the loop. See also
iterator, sequence, and generator.
result = ["0x%02x"
% x for x in range(256) if x % 2 == 0]
generates a list of strings
containing hex numbers (0x..) that are even and in the range from 0 to 255.
The if clause is optional. If omitted, all elements in
range(256)
are processed in that case.
import this
'' at the interactive prompt.
See About this document... for information on suggesting changes.