0

Why Unicode string literals show different id's ? I was hoping the same behavior as that of String literals.

>>> p = 'abcd'
>>> q = 'abcd'
>>> id(p) == id(q)
True
>>> p = u'abcd'
>>> q = u'abcd'
>>> id(p) == id(q)
False

Please provide some pointers on this.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Aashish P
  • 1,894
  • 5
  • 22
  • 36

1 Answers1

0

For the same reason two dicts with the same contents would have different ids: they are distinct objects. I suspect that the non-Unicode string literals being the same object is something of an optimization.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101