mirror of
https://github.com/python/cpython.git
synced 2025-11-15 08:01:29 +00:00
made palatable for latex2html:
removed $math$, added braces to \item[\tt...]
This commit is contained in:
parent
a521c1b751
commit
a54754719d
8 changed files with 186 additions and 172 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
\documentstyle[twoside,11pt,myformat]{report}
|
\documentstyle[twoside,11pt,myformat,html]{report}
|
||||||
|
|
||||||
\title{Python Reference Manual}
|
\title{Python Reference Manual}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
\documentstyle[twoside,11pt,myformat]{report}
|
\documentstyle[twoside,11pt,myformat,html]{report}
|
||||||
|
|
||||||
\title{Python Reference Manual}
|
\title{Python Reference Manual}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -294,11 +294,12 @@ Although both lower case `l' and upper case `L' are allowed as suffix
|
||||||
for long integers, it is strongly recommended to always use `L', since
|
for long integers, it is strongly recommended to always use `L', since
|
||||||
the letter `l' looks too much like the digit `1'.
|
the letter `l' looks too much like the digit `1'.
|
||||||
|
|
||||||
Plain integer decimal literals must be at most $2^{31} - 1$ (i.e., the
|
Plain integer decimal literals must be at most 2147483647 (i.e., the
|
||||||
largest positive integer, assuming 32-bit arithmetic). Plain octal and
|
largest positive integer, using 32-bit arithmetic). Plain octal and
|
||||||
hexadecimal literals may be as large as $2^{32} - 1$, but values
|
hexadecimal literals may be as large as 4294967295, but values larger
|
||||||
larger than $2^{31} - 1$ are converted to a negative value by
|
than 2147483647 are converted to a negative value by subtracting
|
||||||
subtracting $2^{32}$. There is no limit for long integer literals.
|
4294967296. There is no limit for long integer literals apart from
|
||||||
|
what can be stored in available memory.
|
||||||
|
|
||||||
Some examples of plain and long integer literals:
|
Some examples of plain and long integer literals:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,14 +130,14 @@ There are two types of integers:
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[Plain integers]
|
\item[Plain integers]
|
||||||
These represent numbers in the range $-2^{31}$ through $2^{31}-1$.
|
These represent numbers in the range -2147483648 through 2147483647.
|
||||||
(The range may be larger on machines with a larger natural word
|
(The range may be larger on machines with a larger natural word
|
||||||
size, but not smaller.)
|
size, but not smaller.)
|
||||||
When the result of an operation falls outside this range, the
|
When the result of an operation falls outside this range, the
|
||||||
exception \verb@OverflowError@ is raised.
|
exception \verb@OverflowError@ is raised.
|
||||||
For the purpose of shift and mask operations, integers are assumed to
|
For the purpose of shift and mask operations, integers are assumed to
|
||||||
have a binary, 2's complement notation using 32 or more bits, and
|
have a binary, 2's complement notation using 32 or more bits, and
|
||||||
hiding no bits from the user (i.e., all $2^{32}$ different bit
|
hiding no bits from the user (i.e., all 4294967296 different bit
|
||||||
patterns correspond to different values).
|
patterns correspond to different values).
|
||||||
\obindex{plain integer}
|
\obindex{plain integer}
|
||||||
|
|
||||||
|
|
@ -173,9 +173,9 @@ C implementation for the accepted range and handling of overflow.
|
||||||
\item[Sequences]
|
\item[Sequences]
|
||||||
These represent finite ordered sets indexed by natural numbers.
|
These represent finite ordered sets indexed by natural numbers.
|
||||||
The built-in function \verb@len()@ returns the number of elements
|
The built-in function \verb@len()@ returns the number of elements
|
||||||
of a sequence. When this number is $n$, the index set contains
|
of a sequence. When this number is \var{n}, the index set contains
|
||||||
the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence
|
the numbers 0, 1, \ldots, \var{n}-1. Element \var{i} of sequence
|
||||||
\verb@a@ is selected by \verb@a[i]@.
|
\var{a} is selected by \code{\var{a}[\var{i}]}.
|
||||||
\obindex{seqence}
|
\obindex{seqence}
|
||||||
\bifuncindex{len}
|
\bifuncindex{len}
|
||||||
\index{index operation}
|
\index{index operation}
|
||||||
|
|
@ -183,9 +183,10 @@ the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence
|
||||||
\index{subscription}
|
\index{subscription}
|
||||||
|
|
||||||
Sequences also support slicing: \verb@a[i:j]@ selects all elements
|
Sequences also support slicing: \verb@a[i:j]@ selects all elements
|
||||||
with index $k$ such that $i <= k < j$. When used as an expression,
|
with index \var{k} such that \var{i} \code{<=} \var{k} \code{<}
|
||||||
a slice is a sequence of the same type --- this implies that the
|
\var{j}. When used as an expression, a slice is a sequence of the
|
||||||
index set is renumbered so that it starts at 0 again.
|
same type --- this implies that the index set is renumbered so that it
|
||||||
|
starts at 0 again.
|
||||||
\index{slicing}
|
\index{slicing}
|
||||||
|
|
||||||
Sequences are distinguished according to their mutability:
|
Sequences are distinguished according to their mutability:
|
||||||
|
|
@ -599,14 +600,14 @@ For \verb@__str__@, the default is to use \verb@__repr__@.
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __init__(self, args...)]
|
\item[{\tt __init__(self, args...)}]
|
||||||
Called when the instance is created. The arguments are those passed
|
Called when the instance is created. The arguments are those passed
|
||||||
to the class constructor expression. If a base class has an
|
to the class constructor expression. If a base class has an
|
||||||
\code{__init__} method the derived class's \code{__init__} method must
|
\code{__init__} method the derived class's \code{__init__} method must
|
||||||
explicitly call it to ensure proper initialization of the base class
|
explicitly call it to ensure proper initialization of the base class
|
||||||
part of the instance.
|
part of the instance.
|
||||||
|
|
||||||
\item[\tt __del__(self)]
|
\item[{\tt __del__(self)}]
|
||||||
Called when the instance is about to be destroyed. If a base class
|
Called when the instance is about to be destroyed. If a base class
|
||||||
has an \code{__del__} method the derived class's \code{__del__} method
|
has an \code{__del__} method the derived class's \code{__del__} method
|
||||||
must explicitly call it to ensure proper deletion of the base class
|
must explicitly call it to ensure proper deletion of the base class
|
||||||
|
|
@ -621,7 +622,7 @@ Note that \code{del x} doesn't directly call \code{x.__del__} --- the
|
||||||
former decrements the reference count for \code{x} by one, but
|
former decrements the reference count for \code{x} by one, but
|
||||||
\code{x,__del__} is only called when its reference count reaches zero.
|
\code{x,__del__} is only called when its reference count reaches zero.
|
||||||
|
|
||||||
\item[\tt __repr__(self)]
|
\item[{\tt __repr__(self)}]
|
||||||
Called by the \verb@repr()@ built-in function and by string conversions
|
Called by the \verb@repr()@ built-in function and by string conversions
|
||||||
(reverse or backward quotes) to compute the string representation of an object.
|
(reverse or backward quotes) to compute the string representation of an object.
|
||||||
\indexii{string}{conversion}
|
\indexii{string}{conversion}
|
||||||
|
|
@ -629,11 +630,11 @@ Called by the \verb@repr()@ built-in function and by string conversions
|
||||||
\indexii{backward}{quotes}
|
\indexii{backward}{quotes}
|
||||||
\index{back-quotes}
|
\index{back-quotes}
|
||||||
|
|
||||||
\item[\tt __str__(self)]
|
\item[{\tt __str__(self)}]
|
||||||
Called by the \verb@str()@ built-in function and by the \verb@print@
|
Called by the \verb@str()@ built-in function and by the \verb@print@
|
||||||
statement compute the string representation of an object.
|
statement compute the string representation of an object.
|
||||||
|
|
||||||
\item[\tt __cmp__(self, other)]
|
\item[{\tt __cmp__(self, other)}]
|
||||||
Called by all comparison operations. Should return -1 if
|
Called by all comparison operations. Should return -1 if
|
||||||
\verb@self < other@, 0 if \verb@self == other@, +1 if
|
\verb@self < other@, 0 if \verb@self == other@, +1 if
|
||||||
\verb@self > other@. If no \code{__cmp__} operation is defined, class
|
\verb@self > other@. If no \code{__cmp__} operation is defined, class
|
||||||
|
|
@ -642,7 +643,7 @@ instances are compared by object identity (``address'').
|
||||||
exceptions raised by comparisons are ignored, and the objects will be
|
exceptions raised by comparisons are ignored, and the objects will be
|
||||||
considered equal in this case.)
|
considered equal in this case.)
|
||||||
|
|
||||||
\item[\tt __hash__(self)]
|
\item[{\tt __hash__(self)}]
|
||||||
Called for the key object for dictionary operations,
|
Called for the key object for dictionary operations,
|
||||||
and by the built-in function
|
and by the built-in function
|
||||||
\code{hash()}. Should return a 32-bit integer usable as a hash value
|
\code{hash()}. Should return a 32-bit integer usable as a hash value
|
||||||
|
|
@ -659,7 +660,7 @@ implements a \code{__cmp__} method it should not implement
|
||||||
key's hash value is a constant.
|
key's hash value is a constant.
|
||||||
\obindex{dictionary}
|
\obindex{dictionary}
|
||||||
|
|
||||||
\item[\tt __call__(self, *args)]
|
\item[{\tt __call__(self, *args)}]
|
||||||
Called when the instance is ``called'' as a function.
|
Called when the instance is ``called'' as a function.
|
||||||
|
|
||||||
\end{description}
|
\end{description}
|
||||||
|
|
@ -672,7 +673,7 @@ access for class instances.
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __getattr__(self, name)]
|
\item[{\tt __getattr__(self, name)}]
|
||||||
Called when an attribute lookup has not found the attribute in the
|
Called when an attribute lookup has not found the attribute in the
|
||||||
usual places (i.e. it is not an instance attribute nor is it found in
|
usual places (i.e. it is not an instance attribute nor is it found in
|
||||||
the class tree for \code{self}). \code{name} is the attribute name.
|
the class tree for \code{self}). \code{name} is the attribute name.
|
||||||
|
|
@ -687,7 +688,7 @@ Note that at least for instance variables, \code{__getattr__} can fake
|
||||||
total control by simply not inserting any values in the instance
|
total control by simply not inserting any values in the instance
|
||||||
attribute dictionary.
|
attribute dictionary.
|
||||||
|
|
||||||
\item[\tt __setattr__(self, name, value)]
|
\item[{\tt __setattr__(self, name, value)}]
|
||||||
Called when an attribute assignment is attempted. This is called
|
Called when an attribute assignment is attempted. This is called
|
||||||
instead of the normal mechanism (i.e. store the value as an instance
|
instead of the normal mechanism (i.e. store the value as an instance
|
||||||
attribute). \code{name} is the attribute name, \code{value} is the
|
attribute). \code{name} is the attribute name, \code{value} is the
|
||||||
|
|
@ -699,7 +700,7 @@ cause a recursive call. Instead, it should insert the value in the
|
||||||
dictionary of instance attributes, e.g. \code{self.__dict__[name] =
|
dictionary of instance attributes, e.g. \code{self.__dict__[name] =
|
||||||
value}.
|
value}.
|
||||||
|
|
||||||
\item[\tt __delattr__(self, name)]
|
\item[{\tt __delattr__(self, name)}]
|
||||||
Like \code{__setattr__} but for attribute deletion instead of
|
Like \code{__setattr__} but for attribute deletion instead of
|
||||||
assignment.
|
assignment.
|
||||||
|
|
||||||
|
|
@ -710,22 +711,22 @@ assignment.
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __len__(self)]
|
\item[{\tt __len__(self)}]
|
||||||
Called to implement the built-in function \verb@len()@. Should return
|
Called to implement the built-in function \verb@len()@. Should return
|
||||||
the length of the object, an integer \verb@>=@ 0. Also, an object
|
the length of the object, an integer \verb@>=@ 0. Also, an object
|
||||||
whose \verb@__len__()@ method returns 0 is considered to be false in a
|
whose \verb@__len__()@ method returns 0 is considered to be false in a
|
||||||
Boolean context.
|
Boolean context.
|
||||||
|
|
||||||
\item[\tt __getitem__(self, key)]
|
\item[{\tt __getitem__(self, key)}]
|
||||||
Called to implement evaluation of \verb@self[key]@. Note that the
|
Called to implement evaluation of \verb@self[key]@. Note that the
|
||||||
special interpretation of negative keys (if the class wishes to
|
special interpretation of negative keys (if the class wishes to
|
||||||
emulate a sequence type) is up to the \verb@__getitem__@ method.
|
emulate a sequence type) is up to the \verb@__getitem__@ method.
|
||||||
|
|
||||||
\item[\tt __setitem__(self, key, value)]
|
\item[{\tt __setitem__(self, key, value)}]
|
||||||
Called to implement assignment to \verb@self[key]@. Same note as for
|
Called to implement assignment to \verb@self[key]@. Same note as for
|
||||||
\verb@__getitem__@.
|
\verb@__getitem__@.
|
||||||
|
|
||||||
\item[\tt __delitem__(self, key)]
|
\item[{\tt __delitem__(self, key)}]
|
||||||
Called to implement deletion of \verb@self[key]@. Same note as for
|
Called to implement deletion of \verb@self[key]@. Same note as for
|
||||||
\verb@__getitem__@.
|
\verb@__getitem__@.
|
||||||
|
|
||||||
|
|
@ -736,18 +737,18 @@ Called to implement deletion of \verb@self[key]@. Same note as for
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __getslice__(self, i, j)]
|
\item[{\tt __getslice__(self, i, j)}]
|
||||||
Called to implement evaluation of \verb@self[i:j]@. Note that missing
|
Called to implement evaluation of \verb@self[i:j]@. Note that missing
|
||||||
\verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@,
|
\verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@,
|
||||||
respectively, and \verb@len(self)@ has been added (once) to originally
|
respectively, and \verb@len(self)@ has been added (once) to originally
|
||||||
negative \verb@i@ or \verb@j@ by the time this function is called
|
negative \verb@i@ or \verb@j@ by the time this function is called
|
||||||
(unlike for \verb@__getitem__@).
|
(unlike for \verb@__getitem__@).
|
||||||
|
|
||||||
\item[\tt __setslice__(self, i, j, sequence)]
|
\item[{\tt __setslice__(self, i, j, sequence)}]
|
||||||
Called to implement assignment to \verb@self[i:j]@. Same notes as for
|
Called to implement assignment to \verb@self[i:j]@. Same notes as for
|
||||||
\verb@__getslice__@.
|
\verb@__getslice__@.
|
||||||
|
|
||||||
\item[\tt __delslice__(self, i, j)]
|
\item[{\tt __delslice__(self, i, j)}]
|
||||||
Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
||||||
\verb@__getslice__@.
|
\verb@__getslice__@.
|
||||||
|
|
||||||
|
|
@ -758,34 +759,34 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __add__(self, other)]\itemjoin
|
\item[{\tt __add__(self, other)}]\itemjoin
|
||||||
\item[\tt __sub__(self, other)]\itemjoin
|
\item[{\tt __sub__(self, other)}]\itemjoin
|
||||||
\item[\tt __mul__(self, other)]\itemjoin
|
\item[{\tt __mul__(self, other)}]\itemjoin
|
||||||
\item[\tt __div__(self, other)]\itemjoin
|
\item[{\tt __div__(self, other)}]\itemjoin
|
||||||
\item[\tt __mod__(self, other)]\itemjoin
|
\item[{\tt __mod__(self, other)}]\itemjoin
|
||||||
\item[\tt __divmod__(self, other)]\itemjoin
|
\item[{\tt __divmod__(self, other)}]\itemjoin
|
||||||
\item[\tt __pow__(self, other)]\itemjoin
|
\item[{\tt __pow__(self, other)}]\itemjoin
|
||||||
\item[\tt __lshift__(self, other)]\itemjoin
|
\item[{\tt __lshift__(self, other)}]\itemjoin
|
||||||
\item[\tt __rshift__(self, other)]\itemjoin
|
\item[{\tt __rshift__(self, other)}]\itemjoin
|
||||||
\item[\tt __and__(self, other)]\itemjoin
|
\item[{\tt __and__(self, other)}]\itemjoin
|
||||||
\item[\tt __xor__(self, other)]\itemjoin
|
\item[{\tt __xor__(self, other)}]\itemjoin
|
||||||
\item[\tt __or__(self, other)]\itembreak
|
\item[{\tt __or__(self, other)}]\itembreak
|
||||||
Called to implement the binary arithmetic operations (\verb@+@,
|
Called to implement the binary arithmetic operations (\verb@+@,
|
||||||
\verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@,
|
\verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@,
|
||||||
\verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@).
|
\verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@).
|
||||||
|
|
||||||
\item[\tt __neg__(self)]\itemjoin
|
\item[{\tt __neg__(self)}]\itemjoin
|
||||||
\item[\tt __pos__(self)]\itemjoin
|
\item[{\tt __pos__(self)}]\itemjoin
|
||||||
\item[\tt __abs__(self)]\itemjoin
|
\item[{\tt __abs__(self)}]\itemjoin
|
||||||
\item[\tt __invert__(self)]\itembreak
|
\item[{\tt __invert__(self)}]\itembreak
|
||||||
Called to implement the unary arithmetic operations (\verb@-@, \verb@+@,
|
Called to implement the unary arithmetic operations (\verb@-@, \verb@+@,
|
||||||
\verb@abs()@ and \verb@~@).
|
\verb@abs()@ and \verb@~@).
|
||||||
|
|
||||||
\item[\tt __nonzero__(self)]
|
\item[{\tt __nonzero__(self)}]
|
||||||
Called to implement boolean testing; should return 0 or 1. An
|
Called to implement boolean testing; should return 0 or 1. An
|
||||||
alternative name for this method is \verb@__len__@.
|
alternative name for this method is \verb@__len__@.
|
||||||
|
|
||||||
\item[\tt __coerce__(self, other)]
|
\item[{\tt __coerce__(self, other)}]
|
||||||
Called to implement ``mixed-mode'' numeric arithmetic. Should either
|
Called to implement ``mixed-mode'' numeric arithmetic. Should either
|
||||||
return a tuple containing self and other converted to a common numeric
|
return a tuple containing self and other converted to a common numeric
|
||||||
type, or None if no way of conversion is known. When the common type
|
type, or None if no way of conversion is known. When the common type
|
||||||
|
|
@ -803,14 +804,14 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
|
||||||
user-defined classes implementing sequences, mappings or numbers, but
|
user-defined classes implementing sequences, mappings or numbers, but
|
||||||
currently it doesn't --- hence this strange exception.}
|
currently it doesn't --- hence this strange exception.}
|
||||||
|
|
||||||
\item[\tt __int__(self)]\itemjoin
|
\item[{\tt __int__(self)}]\itemjoin
|
||||||
\item[\tt __long__(self)]\itemjoin
|
\item[{\tt __long__(self)}]\itemjoin
|
||||||
\item[\tt __float__(self)]\itembreak
|
\item[{\tt __float__(self)}]\itembreak
|
||||||
Called to implement the built-in functions \verb@int()@, \verb@long()@
|
Called to implement the built-in functions \verb@int()@, \verb@long()@
|
||||||
and \verb@float()@. Should return a value of the appropriate type.
|
and \verb@float()@. Should return a value of the appropriate type.
|
||||||
|
|
||||||
\item[\tt __oct__(self)]\itemjoin
|
\item[{\tt __oct__(self)}]\itemjoin
|
||||||
\item[\tt __hex__(self)]\itembreak
|
\item[{\tt __hex__(self)}]\itembreak
|
||||||
Called to implement the built-in functions \verb@oct()@ and
|
Called to implement the built-in functions \verb@oct()@ and
|
||||||
\verb@hex()@. Should return a string value.
|
\verb@hex()@. Should return a string value.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -307,9 +307,10 @@ The primary must evaluate to a sequence object. The lower and upper
|
||||||
bound expressions, if present, must evaluate to plain integers;
|
bound expressions, if present, must evaluate to plain integers;
|
||||||
defaults are zero and the sequence's length, respectively. If either
|
defaults are zero and the sequence's length, respectively. If either
|
||||||
bound is negative, the sequence's length is added to it. The slicing
|
bound is negative, the sequence's length is added to it. The slicing
|
||||||
now selects all items with index $k$ such that $i <= k < j$ where $i$
|
now selects all items with index \var{k} such that
|
||||||
and $j$ are the specified lower and upper bounds. This may be an
|
\code{\var{i} <= \var{k} < \var{j}} where \var{i}
|
||||||
empty sequence. It is not an error if $i$ or $j$ lie outside the
|
and \var{j} are the specified lower and upper bounds. This may be an
|
||||||
|
empty sequence. It is not an error if \var{i} or \var{j} lie outside the
|
||||||
range of valid indexes (such items don't exist so they aren't
|
range of valid indexes (such items don't exist so they aren't
|
||||||
selected).
|
selected).
|
||||||
|
|
||||||
|
|
@ -477,10 +478,11 @@ arguments are converted to a common type. They shift the first
|
||||||
argument to the left or right by the number of bits given by the
|
argument to the left or right by the number of bits given by the
|
||||||
second argument.
|
second argument.
|
||||||
|
|
||||||
A right shift by $n$ bits is defined as division by $2^n$. A left
|
A right shift by \var{n} bits is defined as division by
|
||||||
shift by $n$ bits is defined as multiplication with $2^n$; for plain
|
\code{pow(2,\var{n})}. A left shift by \var{n} bits is defined as
|
||||||
integers there is no overflow check so this drops bits and flip the
|
multiplication with \code{pow(2,\var{n})}; for plain integers there is
|
||||||
sign if the result is not less than $2^{31}$ in absolute value.
|
no overflow check so this drops bits and flips the sign if the result
|
||||||
|
is not less than \code{pow(2,31)} in absolute value.
|
||||||
|
|
||||||
Negative shift counts raise a \verb@ValueError@ exception.
|
Negative shift counts raise a \verb@ValueError@ exception.
|
||||||
\exindex{ValueError}
|
\exindex{ValueError}
|
||||||
|
|
@ -530,20 +532,21 @@ comp_operator: "<"|">"|"=="|">="|"<="|"<>"|"!="|"is" ["not"]|["not"] "in"
|
||||||
|
|
||||||
Comparisons yield integer values: 1 for true, 0 for false.
|
Comparisons yield integer values: 1 for true, 0 for false.
|
||||||
|
|
||||||
Comparisons can be chained arbitrarily, e.g. $x < y <= z$ is
|
Comparisons can be chained arbitrarily, e.g. \code{x < y <= z} is
|
||||||
equivalent to $x < y$ \verb@and@ $y <= z$, except that $y$ is
|
equivalent to \code{x < y and y <= z}, except that \code{y} is
|
||||||
evaluated only once (but in both cases $z$ is not evaluated at all
|
evaluated only once (but in both cases \code{z} is not evaluated at all
|
||||||
when $x < y$ is found to be false).
|
when \code{x < y} is found to be false).
|
||||||
\indexii{chaining}{comparisons}
|
\indexii{chaining}{comparisons}
|
||||||
|
|
||||||
\catcode`\_=8
|
Formally, if \var{a}, \var{b}, \var{c}, \ldots, \var{y}, \var{z} are
|
||||||
Formally, $e_0 op_1 e_1 op_2 e_2 ...e_{n-1} op_n e_n$ is equivalent to
|
expressions and \var{opa}, \var{opb}, \ldots, \var{opy} are comparison
|
||||||
$e_0 op_1 e_1$ \verb@and@ $e_1 op_2 e_2$ \verb@and@ ... \verb@and@
|
operators, then \var{a opa b opb c} \ldots \var{y opy z} is equivalent
|
||||||
$e_{n-1} op_n e_n$, except that each expression is evaluated at most once.
|
to \var{a opa b} \code{and} \var{b opb c} \code{and} \ldots \code{and}
|
||||||
|
\var{y opy z}, except that each expression is evaluated at most once.
|
||||||
|
|
||||||
Note that $e_0 op_1 e_1 op_2 e_2$ does not imply any kind of comparison
|
Note that \var{a opa b opb c} doesn't imply any kind of comparison
|
||||||
between $e_0$ and $e_2$, e.g. $x < y > z$ is perfectly legal.
|
between \var{a} and \var{c}, so that e.g.\ \code{x < y > z} is
|
||||||
\catcode`\_=12
|
perfectly legal (though perhaps not pretty).
|
||||||
|
|
||||||
The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with
|
The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with
|
||||||
C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below
|
C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below
|
||||||
|
|
@ -557,7 +560,7 @@ ordered consistently but arbitrarily.
|
||||||
|
|
||||||
(This unusual definition of comparison is done to simplify the
|
(This unusual definition of comparison is done to simplify the
|
||||||
definition of operations like sorting and the \verb@in@ and
|
definition of operations like sorting and the \verb@in@ and
|
||||||
\verb@not in@ operators.)
|
\verb@not@ \verb@in@ operators.)
|
||||||
|
|
||||||
Comparison of objects of the same type depends on the type:
|
Comparison of objects of the same type depends on the type:
|
||||||
|
|
||||||
|
|
@ -592,11 +595,12 @@ execution of a program.
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
The operators \verb@in@ and \verb@not in@ test for sequence
|
The operators \verb@in@ and \verb@not in@ test for sequence
|
||||||
membership: if $y$ is a sequence, $x ~\verb@in@~ y$ is true if and
|
membership: if \var{y} is a sequence, \code{\var{x} in \var{y}} is
|
||||||
only if there exists an index $i$ such that $x = y[i]$.
|
true if and only if there exists an index \var{i} such that
|
||||||
$x ~\verb@not in@~ y$ yields the inverse truth value. The exception
|
\code{\var{x} = \var{y}[\var{i}]}.
|
||||||
\verb@TypeError@ is raised when $y$ is not a sequence, or when $y$ is
|
\code{\var{x} not in \var{y}} yields the inverse truth value. The
|
||||||
a string and $x$ is not a string of length one.%
|
exception \verb@TypeError@ is raised when \var{y} is not a sequence,
|
||||||
|
or when \var{y} is a string and \var{x} is not a string of length one.%
|
||||||
\footnote{The latter restriction is sometimes a nuisance.}
|
\footnote{The latter restriction is sometimes a nuisance.}
|
||||||
\opindex{in}
|
\opindex{in}
|
||||||
\opindex{not in}
|
\opindex{not in}
|
||||||
|
|
@ -604,8 +608,9 @@ a string and $x$ is not a string of length one.%
|
||||||
\obindex{sequence}
|
\obindex{sequence}
|
||||||
|
|
||||||
The operators \verb@is@ and \verb@is not@ test for object identity:
|
The operators \verb@is@ and \verb@is not@ test for object identity:
|
||||||
$x ~\verb@is@~ y$ is true if and only if $x$ and $y$ are the same
|
\var{x} \code{is} \var{y} is true if and only if \var{x} and \var{y}
|
||||||
object. $x ~\verb@is not@~ y$ yields the inverse truth value.
|
are the same object. \var{x} \code{is not} \var{y} yields the inverse
|
||||||
|
truth value.
|
||||||
\opindex{is}
|
\opindex{is}
|
||||||
\opindex{is not}
|
\opindex{is not}
|
||||||
\indexii{identity}{test}
|
\indexii{identity}{test}
|
||||||
|
|
@ -632,14 +637,14 @@ other values are interpreted as true.
|
||||||
The operator \verb@not@ yields 1 if its argument is false, 0 otherwise.
|
The operator \verb@not@ yields 1 if its argument is false, 0 otherwise.
|
||||||
\opindex{not}
|
\opindex{not}
|
||||||
|
|
||||||
The condition $x ~\verb@and@~ y$ first evaluates $x$; if $x$ is false,
|
The condition \var{x} \verb@and@ \var{y} first evaluates \var{x}; if
|
||||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
\var{x} is false, its value is returned; otherwise, \var{y} is
|
||||||
value is returned.
|
evaluated and the resulting value is returned.
|
||||||
\opindex{and}
|
\opindex{and}
|
||||||
|
|
||||||
The condition $x ~\verb@or@~ y$ first evaluates $x$; if $x$ is true,
|
The condition \var{x} \verb@or@ \var{y} first evaluates \var{x}; if
|
||||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
\var{x} is true, its value is returned; otherwise, \var{y} is
|
||||||
value is returned.
|
evaluated and the resulting value is returned.
|
||||||
\opindex{or}
|
\opindex{or}
|
||||||
|
|
||||||
(Note that \verb@and@ and \verb@or@ do not restrict the value and type
|
(Note that \verb@and@ and \verb@or@ do not restrict the value and type
|
||||||
|
|
|
||||||
11
Doc/ref2.tex
11
Doc/ref2.tex
|
|
@ -294,11 +294,12 @@ Although both lower case `l' and upper case `L' are allowed as suffix
|
||||||
for long integers, it is strongly recommended to always use `L', since
|
for long integers, it is strongly recommended to always use `L', since
|
||||||
the letter `l' looks too much like the digit `1'.
|
the letter `l' looks too much like the digit `1'.
|
||||||
|
|
||||||
Plain integer decimal literals must be at most $2^{31} - 1$ (i.e., the
|
Plain integer decimal literals must be at most 2147483647 (i.e., the
|
||||||
largest positive integer, assuming 32-bit arithmetic). Plain octal and
|
largest positive integer, using 32-bit arithmetic). Plain octal and
|
||||||
hexadecimal literals may be as large as $2^{32} - 1$, but values
|
hexadecimal literals may be as large as 4294967295, but values larger
|
||||||
larger than $2^{31} - 1$ are converted to a negative value by
|
than 2147483647 are converted to a negative value by subtracting
|
||||||
subtracting $2^{32}$. There is no limit for long integer literals.
|
4294967296. There is no limit for long integer literals apart from
|
||||||
|
what can be stored in available memory.
|
||||||
|
|
||||||
Some examples of plain and long integer literals:
|
Some examples of plain and long integer literals:
|
||||||
|
|
||||||
|
|
|
||||||
97
Doc/ref3.tex
97
Doc/ref3.tex
|
|
@ -130,14 +130,14 @@ There are two types of integers:
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[Plain integers]
|
\item[Plain integers]
|
||||||
These represent numbers in the range $-2^{31}$ through $2^{31}-1$.
|
These represent numbers in the range -2147483648 through 2147483647.
|
||||||
(The range may be larger on machines with a larger natural word
|
(The range may be larger on machines with a larger natural word
|
||||||
size, but not smaller.)
|
size, but not smaller.)
|
||||||
When the result of an operation falls outside this range, the
|
When the result of an operation falls outside this range, the
|
||||||
exception \verb@OverflowError@ is raised.
|
exception \verb@OverflowError@ is raised.
|
||||||
For the purpose of shift and mask operations, integers are assumed to
|
For the purpose of shift and mask operations, integers are assumed to
|
||||||
have a binary, 2's complement notation using 32 or more bits, and
|
have a binary, 2's complement notation using 32 or more bits, and
|
||||||
hiding no bits from the user (i.e., all $2^{32}$ different bit
|
hiding no bits from the user (i.e., all 4294967296 different bit
|
||||||
patterns correspond to different values).
|
patterns correspond to different values).
|
||||||
\obindex{plain integer}
|
\obindex{plain integer}
|
||||||
|
|
||||||
|
|
@ -173,9 +173,9 @@ C implementation for the accepted range and handling of overflow.
|
||||||
\item[Sequences]
|
\item[Sequences]
|
||||||
These represent finite ordered sets indexed by natural numbers.
|
These represent finite ordered sets indexed by natural numbers.
|
||||||
The built-in function \verb@len()@ returns the number of elements
|
The built-in function \verb@len()@ returns the number of elements
|
||||||
of a sequence. When this number is $n$, the index set contains
|
of a sequence. When this number is \var{n}, the index set contains
|
||||||
the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence
|
the numbers 0, 1, \ldots, \var{n}-1. Element \var{i} of sequence
|
||||||
\verb@a@ is selected by \verb@a[i]@.
|
\var{a} is selected by \code{\var{a}[\var{i}]}.
|
||||||
\obindex{seqence}
|
\obindex{seqence}
|
||||||
\bifuncindex{len}
|
\bifuncindex{len}
|
||||||
\index{index operation}
|
\index{index operation}
|
||||||
|
|
@ -183,9 +183,10 @@ the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence
|
||||||
\index{subscription}
|
\index{subscription}
|
||||||
|
|
||||||
Sequences also support slicing: \verb@a[i:j]@ selects all elements
|
Sequences also support slicing: \verb@a[i:j]@ selects all elements
|
||||||
with index $k$ such that $i <= k < j$. When used as an expression,
|
with index \var{k} such that \var{i} \code{<=} \var{k} \code{<}
|
||||||
a slice is a sequence of the same type --- this implies that the
|
\var{j}. When used as an expression, a slice is a sequence of the
|
||||||
index set is renumbered so that it starts at 0 again.
|
same type --- this implies that the index set is renumbered so that it
|
||||||
|
starts at 0 again.
|
||||||
\index{slicing}
|
\index{slicing}
|
||||||
|
|
||||||
Sequences are distinguished according to their mutability:
|
Sequences are distinguished according to their mutability:
|
||||||
|
|
@ -599,14 +600,14 @@ For \verb@__str__@, the default is to use \verb@__repr__@.
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __init__(self, args...)]
|
\item[{\tt __init__(self, args...)}]
|
||||||
Called when the instance is created. The arguments are those passed
|
Called when the instance is created. The arguments are those passed
|
||||||
to the class constructor expression. If a base class has an
|
to the class constructor expression. If a base class has an
|
||||||
\code{__init__} method the derived class's \code{__init__} method must
|
\code{__init__} method the derived class's \code{__init__} method must
|
||||||
explicitly call it to ensure proper initialization of the base class
|
explicitly call it to ensure proper initialization of the base class
|
||||||
part of the instance.
|
part of the instance.
|
||||||
|
|
||||||
\item[\tt __del__(self)]
|
\item[{\tt __del__(self)}]
|
||||||
Called when the instance is about to be destroyed. If a base class
|
Called when the instance is about to be destroyed. If a base class
|
||||||
has an \code{__del__} method the derived class's \code{__del__} method
|
has an \code{__del__} method the derived class's \code{__del__} method
|
||||||
must explicitly call it to ensure proper deletion of the base class
|
must explicitly call it to ensure proper deletion of the base class
|
||||||
|
|
@ -621,7 +622,7 @@ Note that \code{del x} doesn't directly call \code{x.__del__} --- the
|
||||||
former decrements the reference count for \code{x} by one, but
|
former decrements the reference count for \code{x} by one, but
|
||||||
\code{x,__del__} is only called when its reference count reaches zero.
|
\code{x,__del__} is only called when its reference count reaches zero.
|
||||||
|
|
||||||
\item[\tt __repr__(self)]
|
\item[{\tt __repr__(self)}]
|
||||||
Called by the \verb@repr()@ built-in function and by string conversions
|
Called by the \verb@repr()@ built-in function and by string conversions
|
||||||
(reverse or backward quotes) to compute the string representation of an object.
|
(reverse or backward quotes) to compute the string representation of an object.
|
||||||
\indexii{string}{conversion}
|
\indexii{string}{conversion}
|
||||||
|
|
@ -629,11 +630,11 @@ Called by the \verb@repr()@ built-in function and by string conversions
|
||||||
\indexii{backward}{quotes}
|
\indexii{backward}{quotes}
|
||||||
\index{back-quotes}
|
\index{back-quotes}
|
||||||
|
|
||||||
\item[\tt __str__(self)]
|
\item[{\tt __str__(self)}]
|
||||||
Called by the \verb@str()@ built-in function and by the \verb@print@
|
Called by the \verb@str()@ built-in function and by the \verb@print@
|
||||||
statement compute the string representation of an object.
|
statement compute the string representation of an object.
|
||||||
|
|
||||||
\item[\tt __cmp__(self, other)]
|
\item[{\tt __cmp__(self, other)}]
|
||||||
Called by all comparison operations. Should return -1 if
|
Called by all comparison operations. Should return -1 if
|
||||||
\verb@self < other@, 0 if \verb@self == other@, +1 if
|
\verb@self < other@, 0 if \verb@self == other@, +1 if
|
||||||
\verb@self > other@. If no \code{__cmp__} operation is defined, class
|
\verb@self > other@. If no \code{__cmp__} operation is defined, class
|
||||||
|
|
@ -642,7 +643,7 @@ instances are compared by object identity (``address'').
|
||||||
exceptions raised by comparisons are ignored, and the objects will be
|
exceptions raised by comparisons are ignored, and the objects will be
|
||||||
considered equal in this case.)
|
considered equal in this case.)
|
||||||
|
|
||||||
\item[\tt __hash__(self)]
|
\item[{\tt __hash__(self)}]
|
||||||
Called for the key object for dictionary operations,
|
Called for the key object for dictionary operations,
|
||||||
and by the built-in function
|
and by the built-in function
|
||||||
\code{hash()}. Should return a 32-bit integer usable as a hash value
|
\code{hash()}. Should return a 32-bit integer usable as a hash value
|
||||||
|
|
@ -659,7 +660,7 @@ implements a \code{__cmp__} method it should not implement
|
||||||
key's hash value is a constant.
|
key's hash value is a constant.
|
||||||
\obindex{dictionary}
|
\obindex{dictionary}
|
||||||
|
|
||||||
\item[\tt __call__(self, *args)]
|
\item[{\tt __call__(self, *args)}]
|
||||||
Called when the instance is ``called'' as a function.
|
Called when the instance is ``called'' as a function.
|
||||||
|
|
||||||
\end{description}
|
\end{description}
|
||||||
|
|
@ -672,7 +673,7 @@ access for class instances.
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __getattr__(self, name)]
|
\item[{\tt __getattr__(self, name)}]
|
||||||
Called when an attribute lookup has not found the attribute in the
|
Called when an attribute lookup has not found the attribute in the
|
||||||
usual places (i.e. it is not an instance attribute nor is it found in
|
usual places (i.e. it is not an instance attribute nor is it found in
|
||||||
the class tree for \code{self}). \code{name} is the attribute name.
|
the class tree for \code{self}). \code{name} is the attribute name.
|
||||||
|
|
@ -687,7 +688,7 @@ Note that at least for instance variables, \code{__getattr__} can fake
|
||||||
total control by simply not inserting any values in the instance
|
total control by simply not inserting any values in the instance
|
||||||
attribute dictionary.
|
attribute dictionary.
|
||||||
|
|
||||||
\item[\tt __setattr__(self, name, value)]
|
\item[{\tt __setattr__(self, name, value)}]
|
||||||
Called when an attribute assignment is attempted. This is called
|
Called when an attribute assignment is attempted. This is called
|
||||||
instead of the normal mechanism (i.e. store the value as an instance
|
instead of the normal mechanism (i.e. store the value as an instance
|
||||||
attribute). \code{name} is the attribute name, \code{value} is the
|
attribute). \code{name} is the attribute name, \code{value} is the
|
||||||
|
|
@ -699,7 +700,7 @@ cause a recursive call. Instead, it should insert the value in the
|
||||||
dictionary of instance attributes, e.g. \code{self.__dict__[name] =
|
dictionary of instance attributes, e.g. \code{self.__dict__[name] =
|
||||||
value}.
|
value}.
|
||||||
|
|
||||||
\item[\tt __delattr__(self, name)]
|
\item[{\tt __delattr__(self, name)}]
|
||||||
Like \code{__setattr__} but for attribute deletion instead of
|
Like \code{__setattr__} but for attribute deletion instead of
|
||||||
assignment.
|
assignment.
|
||||||
|
|
||||||
|
|
@ -710,22 +711,22 @@ assignment.
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __len__(self)]
|
\item[{\tt __len__(self)}]
|
||||||
Called to implement the built-in function \verb@len()@. Should return
|
Called to implement the built-in function \verb@len()@. Should return
|
||||||
the length of the object, an integer \verb@>=@ 0. Also, an object
|
the length of the object, an integer \verb@>=@ 0. Also, an object
|
||||||
whose \verb@__len__()@ method returns 0 is considered to be false in a
|
whose \verb@__len__()@ method returns 0 is considered to be false in a
|
||||||
Boolean context.
|
Boolean context.
|
||||||
|
|
||||||
\item[\tt __getitem__(self, key)]
|
\item[{\tt __getitem__(self, key)}]
|
||||||
Called to implement evaluation of \verb@self[key]@. Note that the
|
Called to implement evaluation of \verb@self[key]@. Note that the
|
||||||
special interpretation of negative keys (if the class wishes to
|
special interpretation of negative keys (if the class wishes to
|
||||||
emulate a sequence type) is up to the \verb@__getitem__@ method.
|
emulate a sequence type) is up to the \verb@__getitem__@ method.
|
||||||
|
|
||||||
\item[\tt __setitem__(self, key, value)]
|
\item[{\tt __setitem__(self, key, value)}]
|
||||||
Called to implement assignment to \verb@self[key]@. Same note as for
|
Called to implement assignment to \verb@self[key]@. Same note as for
|
||||||
\verb@__getitem__@.
|
\verb@__getitem__@.
|
||||||
|
|
||||||
\item[\tt __delitem__(self, key)]
|
\item[{\tt __delitem__(self, key)}]
|
||||||
Called to implement deletion of \verb@self[key]@. Same note as for
|
Called to implement deletion of \verb@self[key]@. Same note as for
|
||||||
\verb@__getitem__@.
|
\verb@__getitem__@.
|
||||||
|
|
||||||
|
|
@ -736,18 +737,18 @@ Called to implement deletion of \verb@self[key]@. Same note as for
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __getslice__(self, i, j)]
|
\item[{\tt __getslice__(self, i, j)}]
|
||||||
Called to implement evaluation of \verb@self[i:j]@. Note that missing
|
Called to implement evaluation of \verb@self[i:j]@. Note that missing
|
||||||
\verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@,
|
\verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@,
|
||||||
respectively, and \verb@len(self)@ has been added (once) to originally
|
respectively, and \verb@len(self)@ has been added (once) to originally
|
||||||
negative \verb@i@ or \verb@j@ by the time this function is called
|
negative \verb@i@ or \verb@j@ by the time this function is called
|
||||||
(unlike for \verb@__getitem__@).
|
(unlike for \verb@__getitem__@).
|
||||||
|
|
||||||
\item[\tt __setslice__(self, i, j, sequence)]
|
\item[{\tt __setslice__(self, i, j, sequence)}]
|
||||||
Called to implement assignment to \verb@self[i:j]@. Same notes as for
|
Called to implement assignment to \verb@self[i:j]@. Same notes as for
|
||||||
\verb@__getslice__@.
|
\verb@__getslice__@.
|
||||||
|
|
||||||
\item[\tt __delslice__(self, i, j)]
|
\item[{\tt __delslice__(self, i, j)}]
|
||||||
Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
||||||
\verb@__getslice__@.
|
\verb@__getslice__@.
|
||||||
|
|
||||||
|
|
@ -758,34 +759,34 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
||||||
\item[\tt __add__(self, other)]\itemjoin
|
\item[{\tt __add__(self, other)}]\itemjoin
|
||||||
\item[\tt __sub__(self, other)]\itemjoin
|
\item[{\tt __sub__(self, other)}]\itemjoin
|
||||||
\item[\tt __mul__(self, other)]\itemjoin
|
\item[{\tt __mul__(self, other)}]\itemjoin
|
||||||
\item[\tt __div__(self, other)]\itemjoin
|
\item[{\tt __div__(self, other)}]\itemjoin
|
||||||
\item[\tt __mod__(self, other)]\itemjoin
|
\item[{\tt __mod__(self, other)}]\itemjoin
|
||||||
\item[\tt __divmod__(self, other)]\itemjoin
|
\item[{\tt __divmod__(self, other)}]\itemjoin
|
||||||
\item[\tt __pow__(self, other)]\itemjoin
|
\item[{\tt __pow__(self, other)}]\itemjoin
|
||||||
\item[\tt __lshift__(self, other)]\itemjoin
|
\item[{\tt __lshift__(self, other)}]\itemjoin
|
||||||
\item[\tt __rshift__(self, other)]\itemjoin
|
\item[{\tt __rshift__(self, other)}]\itemjoin
|
||||||
\item[\tt __and__(self, other)]\itemjoin
|
\item[{\tt __and__(self, other)}]\itemjoin
|
||||||
\item[\tt __xor__(self, other)]\itemjoin
|
\item[{\tt __xor__(self, other)}]\itemjoin
|
||||||
\item[\tt __or__(self, other)]\itembreak
|
\item[{\tt __or__(self, other)}]\itembreak
|
||||||
Called to implement the binary arithmetic operations (\verb@+@,
|
Called to implement the binary arithmetic operations (\verb@+@,
|
||||||
\verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@,
|
\verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@,
|
||||||
\verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@).
|
\verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@).
|
||||||
|
|
||||||
\item[\tt __neg__(self)]\itemjoin
|
\item[{\tt __neg__(self)}]\itemjoin
|
||||||
\item[\tt __pos__(self)]\itemjoin
|
\item[{\tt __pos__(self)}]\itemjoin
|
||||||
\item[\tt __abs__(self)]\itemjoin
|
\item[{\tt __abs__(self)}]\itemjoin
|
||||||
\item[\tt __invert__(self)]\itembreak
|
\item[{\tt __invert__(self)}]\itembreak
|
||||||
Called to implement the unary arithmetic operations (\verb@-@, \verb@+@,
|
Called to implement the unary arithmetic operations (\verb@-@, \verb@+@,
|
||||||
\verb@abs()@ and \verb@~@).
|
\verb@abs()@ and \verb@~@).
|
||||||
|
|
||||||
\item[\tt __nonzero__(self)]
|
\item[{\tt __nonzero__(self)}]
|
||||||
Called to implement boolean testing; should return 0 or 1. An
|
Called to implement boolean testing; should return 0 or 1. An
|
||||||
alternative name for this method is \verb@__len__@.
|
alternative name for this method is \verb@__len__@.
|
||||||
|
|
||||||
\item[\tt __coerce__(self, other)]
|
\item[{\tt __coerce__(self, other)}]
|
||||||
Called to implement ``mixed-mode'' numeric arithmetic. Should either
|
Called to implement ``mixed-mode'' numeric arithmetic. Should either
|
||||||
return a tuple containing self and other converted to a common numeric
|
return a tuple containing self and other converted to a common numeric
|
||||||
type, or None if no way of conversion is known. When the common type
|
type, or None if no way of conversion is known. When the common type
|
||||||
|
|
@ -803,14 +804,14 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
|
||||||
user-defined classes implementing sequences, mappings or numbers, but
|
user-defined classes implementing sequences, mappings or numbers, but
|
||||||
currently it doesn't --- hence this strange exception.}
|
currently it doesn't --- hence this strange exception.}
|
||||||
|
|
||||||
\item[\tt __int__(self)]\itemjoin
|
\item[{\tt __int__(self)}]\itemjoin
|
||||||
\item[\tt __long__(self)]\itemjoin
|
\item[{\tt __long__(self)}]\itemjoin
|
||||||
\item[\tt __float__(self)]\itembreak
|
\item[{\tt __float__(self)}]\itembreak
|
||||||
Called to implement the built-in functions \verb@int()@, \verb@long()@
|
Called to implement the built-in functions \verb@int()@, \verb@long()@
|
||||||
and \verb@float()@. Should return a value of the appropriate type.
|
and \verb@float()@. Should return a value of the appropriate type.
|
||||||
|
|
||||||
\item[\tt __oct__(self)]\itemjoin
|
\item[{\tt __oct__(self)}]\itemjoin
|
||||||
\item[\tt __hex__(self)]\itembreak
|
\item[{\tt __hex__(self)}]\itembreak
|
||||||
Called to implement the built-in functions \verb@oct()@ and
|
Called to implement the built-in functions \verb@oct()@ and
|
||||||
\verb@hex()@. Should return a string value.
|
\verb@hex()@. Should return a string value.
|
||||||
|
|
||||||
|
|
|
||||||
69
Doc/ref5.tex
69
Doc/ref5.tex
|
|
@ -307,9 +307,10 @@ The primary must evaluate to a sequence object. The lower and upper
|
||||||
bound expressions, if present, must evaluate to plain integers;
|
bound expressions, if present, must evaluate to plain integers;
|
||||||
defaults are zero and the sequence's length, respectively. If either
|
defaults are zero and the sequence's length, respectively. If either
|
||||||
bound is negative, the sequence's length is added to it. The slicing
|
bound is negative, the sequence's length is added to it. The slicing
|
||||||
now selects all items with index $k$ such that $i <= k < j$ where $i$
|
now selects all items with index \var{k} such that
|
||||||
and $j$ are the specified lower and upper bounds. This may be an
|
\code{\var{i} <= \var{k} < \var{j}} where \var{i}
|
||||||
empty sequence. It is not an error if $i$ or $j$ lie outside the
|
and \var{j} are the specified lower and upper bounds. This may be an
|
||||||
|
empty sequence. It is not an error if \var{i} or \var{j} lie outside the
|
||||||
range of valid indexes (such items don't exist so they aren't
|
range of valid indexes (such items don't exist so they aren't
|
||||||
selected).
|
selected).
|
||||||
|
|
||||||
|
|
@ -477,10 +478,11 @@ arguments are converted to a common type. They shift the first
|
||||||
argument to the left or right by the number of bits given by the
|
argument to the left or right by the number of bits given by the
|
||||||
second argument.
|
second argument.
|
||||||
|
|
||||||
A right shift by $n$ bits is defined as division by $2^n$. A left
|
A right shift by \var{n} bits is defined as division by
|
||||||
shift by $n$ bits is defined as multiplication with $2^n$; for plain
|
\code{pow(2,\var{n})}. A left shift by \var{n} bits is defined as
|
||||||
integers there is no overflow check so this drops bits and flip the
|
multiplication with \code{pow(2,\var{n})}; for plain integers there is
|
||||||
sign if the result is not less than $2^{31}$ in absolute value.
|
no overflow check so this drops bits and flips the sign if the result
|
||||||
|
is not less than \code{pow(2,31)} in absolute value.
|
||||||
|
|
||||||
Negative shift counts raise a \verb@ValueError@ exception.
|
Negative shift counts raise a \verb@ValueError@ exception.
|
||||||
\exindex{ValueError}
|
\exindex{ValueError}
|
||||||
|
|
@ -530,20 +532,21 @@ comp_operator: "<"|">"|"=="|">="|"<="|"<>"|"!="|"is" ["not"]|["not"] "in"
|
||||||
|
|
||||||
Comparisons yield integer values: 1 for true, 0 for false.
|
Comparisons yield integer values: 1 for true, 0 for false.
|
||||||
|
|
||||||
Comparisons can be chained arbitrarily, e.g. $x < y <= z$ is
|
Comparisons can be chained arbitrarily, e.g. \code{x < y <= z} is
|
||||||
equivalent to $x < y$ \verb@and@ $y <= z$, except that $y$ is
|
equivalent to \code{x < y and y <= z}, except that \code{y} is
|
||||||
evaluated only once (but in both cases $z$ is not evaluated at all
|
evaluated only once (but in both cases \code{z} is not evaluated at all
|
||||||
when $x < y$ is found to be false).
|
when \code{x < y} is found to be false).
|
||||||
\indexii{chaining}{comparisons}
|
\indexii{chaining}{comparisons}
|
||||||
|
|
||||||
\catcode`\_=8
|
Formally, if \var{a}, \var{b}, \var{c}, \ldots, \var{y}, \var{z} are
|
||||||
Formally, $e_0 op_1 e_1 op_2 e_2 ...e_{n-1} op_n e_n$ is equivalent to
|
expressions and \var{opa}, \var{opb}, \ldots, \var{opy} are comparison
|
||||||
$e_0 op_1 e_1$ \verb@and@ $e_1 op_2 e_2$ \verb@and@ ... \verb@and@
|
operators, then \var{a opa b opb c} \ldots \var{y opy z} is equivalent
|
||||||
$e_{n-1} op_n e_n$, except that each expression is evaluated at most once.
|
to \var{a opa b} \code{and} \var{b opb c} \code{and} \ldots \code{and}
|
||||||
|
\var{y opy z}, except that each expression is evaluated at most once.
|
||||||
|
|
||||||
Note that $e_0 op_1 e_1 op_2 e_2$ does not imply any kind of comparison
|
Note that \var{a opa b opb c} doesn't imply any kind of comparison
|
||||||
between $e_0$ and $e_2$, e.g. $x < y > z$ is perfectly legal.
|
between \var{a} and \var{c}, so that e.g.\ \code{x < y > z} is
|
||||||
\catcode`\_=12
|
perfectly legal (though perhaps not pretty).
|
||||||
|
|
||||||
The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with
|
The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with
|
||||||
C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below
|
C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below
|
||||||
|
|
@ -557,7 +560,7 @@ ordered consistently but arbitrarily.
|
||||||
|
|
||||||
(This unusual definition of comparison is done to simplify the
|
(This unusual definition of comparison is done to simplify the
|
||||||
definition of operations like sorting and the \verb@in@ and
|
definition of operations like sorting and the \verb@in@ and
|
||||||
\verb@not in@ operators.)
|
\verb@not@ \verb@in@ operators.)
|
||||||
|
|
||||||
Comparison of objects of the same type depends on the type:
|
Comparison of objects of the same type depends on the type:
|
||||||
|
|
||||||
|
|
@ -592,11 +595,12 @@ execution of a program.
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
The operators \verb@in@ and \verb@not in@ test for sequence
|
The operators \verb@in@ and \verb@not in@ test for sequence
|
||||||
membership: if $y$ is a sequence, $x ~\verb@in@~ y$ is true if and
|
membership: if \var{y} is a sequence, \code{\var{x} in \var{y}} is
|
||||||
only if there exists an index $i$ such that $x = y[i]$.
|
true if and only if there exists an index \var{i} such that
|
||||||
$x ~\verb@not in@~ y$ yields the inverse truth value. The exception
|
\code{\var{x} = \var{y}[\var{i}]}.
|
||||||
\verb@TypeError@ is raised when $y$ is not a sequence, or when $y$ is
|
\code{\var{x} not in \var{y}} yields the inverse truth value. The
|
||||||
a string and $x$ is not a string of length one.%
|
exception \verb@TypeError@ is raised when \var{y} is not a sequence,
|
||||||
|
or when \var{y} is a string and \var{x} is not a string of length one.%
|
||||||
\footnote{The latter restriction is sometimes a nuisance.}
|
\footnote{The latter restriction is sometimes a nuisance.}
|
||||||
\opindex{in}
|
\opindex{in}
|
||||||
\opindex{not in}
|
\opindex{not in}
|
||||||
|
|
@ -604,8 +608,9 @@ a string and $x$ is not a string of length one.%
|
||||||
\obindex{sequence}
|
\obindex{sequence}
|
||||||
|
|
||||||
The operators \verb@is@ and \verb@is not@ test for object identity:
|
The operators \verb@is@ and \verb@is not@ test for object identity:
|
||||||
$x ~\verb@is@~ y$ is true if and only if $x$ and $y$ are the same
|
\var{x} \code{is} \var{y} is true if and only if \var{x} and \var{y}
|
||||||
object. $x ~\verb@is not@~ y$ yields the inverse truth value.
|
are the same object. \var{x} \code{is not} \var{y} yields the inverse
|
||||||
|
truth value.
|
||||||
\opindex{is}
|
\opindex{is}
|
||||||
\opindex{is not}
|
\opindex{is not}
|
||||||
\indexii{identity}{test}
|
\indexii{identity}{test}
|
||||||
|
|
@ -632,14 +637,14 @@ other values are interpreted as true.
|
||||||
The operator \verb@not@ yields 1 if its argument is false, 0 otherwise.
|
The operator \verb@not@ yields 1 if its argument is false, 0 otherwise.
|
||||||
\opindex{not}
|
\opindex{not}
|
||||||
|
|
||||||
The condition $x ~\verb@and@~ y$ first evaluates $x$; if $x$ is false,
|
The condition \var{x} \verb@and@ \var{y} first evaluates \var{x}; if
|
||||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
\var{x} is false, its value is returned; otherwise, \var{y} is
|
||||||
value is returned.
|
evaluated and the resulting value is returned.
|
||||||
\opindex{and}
|
\opindex{and}
|
||||||
|
|
||||||
The condition $x ~\verb@or@~ y$ first evaluates $x$; if $x$ is true,
|
The condition \var{x} \verb@or@ \var{y} first evaluates \var{x}; if
|
||||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
\var{x} is true, its value is returned; otherwise, \var{y} is
|
||||||
value is returned.
|
evaluated and the resulting value is returned.
|
||||||
\opindex{or}
|
\opindex{or}
|
||||||
|
|
||||||
(Note that \verb@and@ and \verb@or@ do not restrict the value and type
|
(Note that \verb@and@ and \verb@or@ do not restrict the value and type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue