>>
>
..
.
.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.
The implicit conversion of an instance of one type to another during an
operation which involves two arguments of the same type. For example,
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), 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 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 programmer, e.g., float(3)+4.5
rather than just
3+4.5
.
An extension of the familiar real number system in which all numbers are
expressed as a sum of a real part and an imaginary part. Imaginary numbers
are real multiples of the imaginary unit (the square root of -1
),
often written i
in mathematics or j
in engineering.
Python has builtin support for complex numbers, which are written with this
latter notation; the imaginary part is written with a j
suffix,
e.g., 3+1j
. To get access to complex equivalents of the
math module, use cmath. Use of complex numbers is a
fairly advanced mathematical feature. If you're not aware of a need for them,
it's almost certain you can safely ignore them.
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)
>>> sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81 285
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, 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 __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.
ÒëÕߣºÁõöÎ(march.liu AT gmail DOT com) ÓÉ£ºlimodouת(limodou AT gmail DOT com)