Kaydet (Commit) 1156f623 authored tarafından Fred Drake's avatar Fred Drake

Many small clarifications, including many suggested by email.

üst b96e0e5e
...@@ -676,11 +676,10 @@ converted to a common type. ...@@ -676,11 +676,10 @@ converted to a common type.
\section{Comparisons\label{comparisons}} \section{Comparisons\label{comparisons}}
\index{comparison} \index{comparison}
Contrary to \C, all comparison operations in Python have the same Unlike C, all comparison operations in Python have the same priority,
priority, which is lower than that of any arithmetic, shifting or which is lower than that of any arithmetic, shifting or bitwise
bitwise operation. Also contrary to \C, expressions like operation. Also unlike C, expressions like \code{a < b < c} have the
\code{a < b < c} have the interpretation that is conventional in interpretation that is conventional in mathematics:
mathematics:
\indexii{C}{language} \indexii{C}{language}
\begin{verbatim} \begin{verbatim}
...@@ -708,11 +707,12 @@ perfectly legal (though perhaps not pretty). ...@@ -708,11 +707,12 @@ perfectly legal (though perhaps not pretty).
The forms \code{<>} and \code{!=} are equivalent; for consistency with The forms \code{<>} and \code{!=} are equivalent; for consistency with
C, \code{!=} is preferred; where \code{!=} is mentioned below C, \code{!=} is preferred; where \code{!=} is mentioned below
\code{<>} is also acceptable. At some point in the (far) future, \code{<>} is also accepted. The \code{<>} spelling is considered
\code{<>} may become obsolete. obsolescent.
The operators \texttt{"<", ">", "==", ">=", "<="}, and \texttt{"!="} compare The operators \code{<}, \code{>}, \code{==}, \code{>=}, \code{<=}, and
the values of two objects. The objects needn't have the same type. \code{!=} compare
the values of two objects. The objects need not have the same type.
If both are numbers, they are coverted to a common type. Otherwise, If both are numbers, they are coverted to a common type. Otherwise,
objects of different types \emph{always} compare unequal, and are objects of different types \emph{always} compare unequal, and are
ordered consistently but arbitrarily. ordered consistently but arbitrarily.
...@@ -732,7 +732,8 @@ Numbers are compared arithmetically. ...@@ -732,7 +732,8 @@ Numbers are compared arithmetically.
\item \item
Strings are compared lexicographically using the numeric equivalents Strings are compared lexicographically using the numeric equivalents
(the result of the built-in function \function{ord()}) of their (the result of the built-in function \function{ord()}) of their
characters. characters. Unicode and 8-bit strings are fully interoperable in this
behavior.
\item \item
Tuples and lists are compared lexicographically using comparison of Tuples and lists are compared lexicographically using comparison of
...@@ -765,19 +766,19 @@ For the list, tuple types, \code{\var{x} in \var{y}} is true if and only ...@@ -765,19 +766,19 @@ For the list, tuple types, \code{\var{x} in \var{y}} is true if and only
if there exists such an index \var{i} such that if there exists such an index \var{i} such that
\code{var{x} == \var{y}[\var{i}]} is true. \code{var{x} == \var{y}[\var{i}]} is true.
For the Unicode and string types, \code{\var{x} in \var{y}} is true if and only For the Unicode and string types, \code{\var{x} in \var{y}} is true if
if there exists such an index \var{i} such that and only if there exists an index \var{i} such that \code{\var{x} ==
\code{var{x} == \var{y}[\var{i}]} is true. If \code{\var{x}} is not \var{y}[\var{i}]} is true. If \code{\var{x}} is not a string or
a string of length \code{1} or a unicode object of length \code{1}, Unicode object of length \code{1}, a \exception{TypeError} exception
a \exception{TypeError} exception is raised. is raised.
For user-defined classes which define the \method{__contains__()} method, For user-defined classes which define the \method{__contains__()} method,
\code{\var{x} in \var{y}} is true if and only if \code{\var{x} in \var{y}} is true if and only if
\code{\var{y}.__contains__(\var{x})} is true. \code{\var{y}.__contains__(\var{x})} is true.
For user-defined classes which do not define \method{__contains__()} and For user-defined classes which do not define \method{__contains__()} and
do define \var{__getitem__}, \code{\var{x} in \var{y}} is true if and only do define \method{__getitem__()}, \code{\var{x} in \var{y}} is true if
if there is a non-negative integer index \var{i} such that and only if there is a non-negative integer index \var{i} such that
\code{\var{x} == \var{y}[\var{i}]}, and all lower integer indices \code{\var{x} == \var{y}[\var{i}]}, and all lower integer indices
do not raise \exception{IndexError} exception. (If any other exception do not raise \exception{IndexError} exception. (If any other exception
is raised, it is as if \keyword{in} raised that exception). is raised, it is as if \keyword{in} raised that exception).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment