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
  • 14,735
  • 16
  • 96
  • 147
Aashish P
  • 1,772
  • 5
  • 20
  • 35

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
  • 46,905
  • 10
  • 55
  • 92