A
Avetis KAZARIAN
After reading the discussion about the same subject ( From: "Thomas
Moore" <[email protected]> Date: Tue, 1 Nov 2005 21:45:56
+0800 ), I tried myself some tests with some confusing results (I'm a
beginner with Python, I'm coming from PHP)
# 1. Short alpha-numeric String without space
a = "b747"
b = "b747"
True
# 2. Long alpha-numeric String without space
a =
"averylongstringbutreallyaveryveryverylongstringwithabout68characters"
b =
"averylongstringbutreallyaveryveryverylongstringwithabout68characters"
True
# 3. Short alpha-numeric String with space
a = "x y"
b = "x y"
False
# 4. Long alpha-numeric String with space
a = "I love Python it s so much better than PHP but sometimes
confusing"
b = "I love Python it s so much better than PHP but sometimes
confusing"
False
# 5. Empty String
a = ""
b = ""
True
# 6. Whitecharacter String : space
a = " "
b = " "
False
# 7. Whitecharacter String : new line
a = "\n"
b = "\n"
False
# 8. Non-ASCII without space
a = "é"
b = "é"
False
# 9. Non-ASCII with space
a = "é à"
b = "é à"
False
It seems that any strict ASCII alpha-numeric string is instantiated as
an unique object, like a "singleton" ( a = "x" and b = "x" => a is b )
and that any non strict ASCII alpha-numeric string is instantiated as
a new object every time with a new id.
Conclusion :
How does Python manage strings as objects?
Moore" <[email protected]> Date: Tue, 1 Nov 2005 21:45:56
+0800 ), I tried myself some tests with some confusing results (I'm a
beginner with Python, I'm coming from PHP)
# 1. Short alpha-numeric String without space
a = "b747"
b = "b747"
True
# 2. Long alpha-numeric String without space
a =
"averylongstringbutreallyaveryveryverylongstringwithabout68characters"
b =
"averylongstringbutreallyaveryveryverylongstringwithabout68characters"
True
# 3. Short alpha-numeric String with space
a = "x y"
b = "x y"
False
# 4. Long alpha-numeric String with space
a = "I love Python it s so much better than PHP but sometimes
confusing"
b = "I love Python it s so much better than PHP but sometimes
confusing"
False
# 5. Empty String
a = ""
b = ""
True
# 6. Whitecharacter String : space
a = " "
b = " "
False
# 7. Whitecharacter String : new line
a = "\n"
b = "\n"
False
# 8. Non-ASCII without space
a = "é"
b = "é"
False
# 9. Non-ASCII with space
a = "é à"
b = "é à"
False
It seems that any strict ASCII alpha-numeric string is instantiated as
an unique object, like a "singleton" ( a = "x" and b = "x" => a is b )
and that any non strict ASCII alpha-numeric string is instantiated as
a new object every time with a new id.
Conclusion :
How does Python manage strings as objects?