<p><span class="h-card" translate="no"><a href="https://mastodon.social/@dabeaz" class="u-url mention">@<span>dabeaz</span></a></span> <span class="h-card" translate="no"><a href="https://ciberlandia.pt/@villares" class="u-url mention">@<span>villares</span></a></span> this has to do with Python's "interning", done to preserve memory and efficiency. Rather than store multiple copies of static variables, all variables will point to the same set of values.</p><p>```<br />a = 42<br />b = 42<br />c = float('nan')<br />d = float('nan')</p><p>assert id(a) == id(b)<br />assert id(c) != id(d)<br />```</p><p>Interning doesn't happen for nan values because it relies on the fact that the two values are equal.</p>