[Tutor] Equality of numbers and Strings

2011-01-10 Thread Karim
Hello All, I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical (numerically). I get the same object

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Emile van Sebille
On 1/10/2011 8:07 AM Karim said... Hello All, I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread bob gailer
On 1/10/2011 11:07 AM, Karim wrote: Hello All, I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread bob gailer
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

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread wesley chun
On Mon, Jan 10, 2011 at 8:54 AM, bob gailer bgai...@gmail.com wrote: On 1/10/2011 11:07 AM, Karim wrote: s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical (numerically). Python interns certain literal strings -

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Emile van Sebille
On 1/10/2011 9:23 AM bob gailer said... 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)

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Stefan Behnel
Emile van Sebille, 10.01.2011 18:42: On 1/10/2011 9:23 AM bob gailer said... 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

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Stefan Behnel
Karim, 10.01.2011 17:07: I am not a beginner in Python language but I discovered a hidden property of immutable elements as Numbers and Strings. s ='xyz' t = str('xyz') id(s) == id(t) True Thus if I create 2 different instances of string if the string is identical (numerically). I get the

Re: [Tutor] Equality of numbers and Strings

2011-01-10 Thread Karim
Many thanks Emile, Bob, Stefan, Wesley! Now, I see now that the point is more related to implementation details and optimization instead of a true property. But it could mistaken people not aware. Regards Karim On 01/10/2011 06:56 PM, Stefan Behnel wrote: Karim, 10.01.2011 17:07: I am not