Reputation: 55
in addition to the answers provided here
For example :
q = "asdasdasdsadsadsadsadsadsadsadsadsad"
a = "asdasdasdsadsadsadsadsadsadsadsadsad"
>>> a is q
True
even though the strings are long(way longer than 4 characters), python still points to the same object in memory no matter how many times i concatenate "asd", but...
..if i add,lets say "e", that makes the unique characters 4 (a,s,d and e) and python now creates a value object in heap.
q = "asdasdasdsadsadsadsadsadsadsadsadsade"
a = "asdasdasdsadsadsadsadsadsadsadsadsade"
>>> a is q
False
Interesting.
Can someone elaborate on this?
Edit:
Now it is True, but if I add a special character in both variables then it returns False
Upvotes: 2
Views: 49