'1' + 1 ==> True ???
Isaac To
kkto at csis.hku.hk
Thu Mar 18 21:18:38 EST 2004
>>>>> "Peter" == Peter Maas <fpetermaas at netscape.net> writes:
Peter> The mapping of '1' to 0x31 is defined by ASCII which is used by
Peter> C. If a C instruction retrieves a char it reads data from an
Peter> adress and if there is a 0x31 stored at the adress C treats it as
Peter> '1'. My short form of this is "'1' is 0x31 in memory".
In the original post, the literal '1' need not be (and probably is not)
stored in memory at all. In this case you have no "address". But that is
subtle details. The main point is still that, in the world of C, '1' and 49
are completely indistinguishable *values*. Or put it in another way, in C,
a character literal does *not* represent a "character". Instead, the
literal '1' is just "the *number* which, by the most common convention used
by the computer hardware, is interpreted as the character representing the
arabic numeral 'one'". It is a *number*. That's the reason why you can add
up 1 and '1'. Not because C "ignores type information and care only the
memory". (Try adding up 2.5 and "1").
It is an important distinction: even in C we talk about the abstraction of
expression, and the abstraction of character literal is a number, not a
"character" in the eye of a regular Python programmer.
Peter> I didn't talk about different programs but different machines
Peter> (architecture). Python Standard Library (Comparison) has this
Peter> Implementation note: Objects of different types except numbers
Peter> are ordered by their type names;
As you said, it is "implementation note". Also, about C your argument is
that different platforms can have different encoding in their characters,
and thus different ordering. Since type names are expressed in characters,
it follows directly that names of types in Python also has such dependency.
Regards,
Isaac.
More information about the Python-list
mailing list