check if object is number

Steven Bethard steven.bethard at gmail.com
Fri Feb 11 18:19:56 EST 2005


George Sakkis wrote:
> For the record, here's the arbitrary and undocumented (?) order
> among some main builtin types:
> 
>>>>None < 0 == 0.0 < {} < [] < ""  < ()

If you're curious, you can check the source code.  Look for 
default_3way_compare in object.c.  Basically the rundown for dissimilar 
types is:

* None is smaller than anything
* Numbers (as defined by PyNumber_Check) are smaller than everything else
* All other types are compared by type name (and by the address of the 
type object if the type names are the same).

Pretty arbitrary, yeah. ;)

Steve



More information about the Python-list mailing list