Python built-in id() not consistent:

Posted by Dannellyz on Stack Overflow See other posts from Stack Overflow or by Dannellyz
Published on 2013-11-01T15:22:21Z Indexed on 2013/11/01 15:54 UTC
Read the original article Hit count: 166

Filed under:
|

Hoping someone can explain the following discrepancy:

>>> s1 = "Cyber security"
>>> s2 = "Cyber security"
>>> id(s1) == id(s1)
True
>>> id(s1) == id(s2)
False
>>> s1 = "cyber"
>>> s2 = "cyber"
>>> id(s1) == id(s2)
True
>>> s2 = "cyber "
>>> s2 = "cyber "
>>> id(s1) == id(s2)
False

Why does the space make the id() False, yet different variables with no spaces are True?

© Stack Overflow or respective owner

Related posts about python-3.x

Related posts about built-in