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
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
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
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
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 -
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)
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
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
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