'1' + 1 ==> True ???

Peter Maas fpetermaas at netscape.net
Thu Mar 18 20:46:04 CET 2004


Isaac To schrieb:
>     Peter> That's not really a conversion. '1' is 0x31 in memory and 0x31 >
>     Peter> 1.
> 
> That's really not a conversion, but not because '1' is 0x31 in memory.  It
> is because C defines '1' to be equivalent to (in every respect, including
> type) the integer to represent it---which is 49 (0x31) in most computers we
> use today. 

The mapping of '1' to 0x31 is defined by ASCII which is used by C. If a C
instruction retrieves a char it reads data from an adress and if there is
a 0x31 stored at the adress C treats it as '1'. My short form of this is
"'1' is 0x31 in memory".

>     Peter> Unlike C, Python's comparison results for different types are
>     Peter> defined in a strange but archicture independent way, see Python
>     Peter> Library Reference 2.3.3.
> 
> Also untrue.  Python's comparison result is dependent on implementation, so
> even in the same computer, two different Python implementation can give you
> different results; and you cannot make any assumption in different
> platforms.

I didn't talk about different programs but different machines (architecture).
Python Standard Library (Comparison) has this

Implementation note: Objects of different types except numbers are
ordered by their type names;

Mit freundlichen Gruessen,

Peter Maas


> Regards,
> Isaac.


-- 
Mit freundlichen Gruessen,

Peter Maas

-- 
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------



More information about the Python-list mailing list