"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> you're confusing the external representation of something with the 
> internal
> data model.
>
> consider this:
>
>    >>> "hello"
>    >>> 'hello'
>    >>> "hell\x6f"
>    >>> "hell\157"
>    >>> "hell" + "o"
>    >>> 'h' 'e' 'l' 'l' 'o'
>
> the above are six ways to write the same string literal in Python.

Minor nit: I believe 'hell' + 'o' is two string literals and a runtime 
concatenation operation.  Perhaps you meant 'hell' 'o', without the '+', 
which I believe is joined to one literal at parsing or compilation time.

> all these result
> in a five-character string containing the letters "h", "e", "l", "l", and 
> "o".
> if you type the above at a python prompt,
> you'll find that Python echoes the strings back as
> 'hello' in all six cases.

Nit aside, this is a valuable point that bears repeating.  Another example 
of one internal versus multiple external that confuses many is the 
following:
 1.1 == 1.1000000000000001 # True

The mapping of external to internal is many-to-one for both strings and 
floats and therefore *cannot* be exactly inverted!  (Or round-tripped.) So 
Python has to somehow choose one of the possible external forms that would 
generate the internal form.

Terry J. Reedy




-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to