GNU Info

Info Node: (python2.1-lib.info)Comparisons

(python2.1-lib.info)Comparisons


Next: Numeric Types Prev: Boolean Operations Up: Built-in Types
Enter node , (file) or (file)node

Comparisons
-----------

Comparison operations are supported by all objects.  They all have the
same priority (which is higher than that of the Boolean operations).
Comparisons can be chained arbitrarily; for example, `X < Y <= Z' is
equivalent to `X < Y and Y <= Z', except that Y is evaluated only once
(but in both cases Z is not evaluated at all when `X < Y' is found to
be false).

This table summarizes the comparison operations:

Operation                Meaning                  Notes
------                   -----                    -----
<                        strictly less than       
<=                       less than or equal       
>                        strictly greater than    
>=                       greater than or equal    
==                       equal                    
!=                       not equal                (1)
<>                       not equal                (1)
is                       object identity          
is not                   negated object identity  

Notes:

`(1)'
     `<>' and `!=' are alternate spellings for the same operator.  (I
     couldn't choose between ABC and C! :-) `!=' is the preferred
     spelling; `<>' is obsolescent.

Objects of different types, except different numeric types, never
compare equal; such objects are ordered consistently but arbitrarily
(so that sorting a heterogeneous array yields a consistent result).
Furthermore, some types (for example, file objects) support only a
degenerate notion of comparison where any two objects of that type are
unequal.  Again, such objects are ordered arbitrarily but consistently.

Instances of a class normally compare as non-equal unless the class
defines the `__cmp__()' method.  Refer to the  for information on the
use of this method to effect object comparisons.

*Implementation note:* Objects of different types except numbers are
ordered by their type names; objects of the same types that don't
support proper comparison are ordered by their address.

Two more operations with the same syntactic priority, `in'  and `not in'
, are supported only by sequence types (below).


automatically generated by info2www version 1.2.2.9