How does python know?

Tobiah toby at tobiah.org
Wed Feb 12 15:17:20 EST 2014


I do this:

a = 'lasdfjlasdjflaksdjfl;akjsdf;kljasdl;kfjasl'
b = 'lasdfjlasdjflaksdjfl;akjsdf;kljasdl;kfjasl'

print
print id(a)
print id(b)


And get this:

True
140329184721376
140329184721376


This works for longer strings.  Does python
compare a new string to every other string
I've made in order to determine whether it
needs to create a new object?

Thanks,

Tobiah



More information about the Python-list mailing list