[Tutor] Equality of numbers and Strings
bob gailer
bgailer at gmail.com
Mon Jan 10 18:23:46 CET 2011
On 1/10/2011 11:51 AM, Emile van Sebille wrote:
>
> well, not predictably unless you understand the specifics of the
> implementation you're running under.
>
>
> >>> from string import letters
> >>> longstring = letters*100
> >>> otherstring = letters*100
> >>> id(longstring)
> 12491608
> >>> id (otherstring)
> 12100288
> >>> shortstring = letters[:]
> >>> id(letters)
> 11573952
> >>> id(shortstring)
> 11573952
> >>>
>
In my experiment I found that using * to replicate gave different
results than using the exact literal. That is why in the program I
posted I used the equivalent of eval("'" + letters*n + "'") which gives
different results than eval("letters*n")!
[snip]
--
Bob Gailer
919-636-4239
Chapel Hill NC
More information about the Tutor
mailing list