Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:2.2.2 Boolean OperationsUp:2.2 Built-in TypesNext:2.2.4 Numeric Types

 
2.2.3 Comparisons

Comparison operations are supported by all objects. They all have thesame priority (which is higher than that of the Boolean operations).Comparisons can be chained arbitrarily; for example,x <y <=z is equivalent tox <y andy <=z, except thaty is evaluated only once (butin both casesz is not evaluated at all whenx <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)
isobject identity 
is notnegated 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, nevercompare 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 adegenerate notion of comparison where any two objects of that type areunequal. Again, such objects are ordered arbitrarily butconsistently. 

Instances of a class normally compare as non-equal unless the class defines the__cmp__() method. Refer to thePython Reference Manual forinformation on the use of this method to effect object comparisons.

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

Two more operations with the same syntactic priority,"in" and "not in" , are supportedonly by sequence types (below).


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:2.2.2 Boolean OperationsUp:2.2 Built-in TypesNext:2.2.4 Numeric Types
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp