Python Can Be Weird – Let's Look at Some Peculiar Examples
Sometimes Python behaves in ways that make you do a double-take. Here are four classic curiosities – and why they are actually perfectly logical.

Python is a fantastic language, but sometimes it behaves in ways that make you do a double-take. Here are four classics – and the explanation behind them.
Example 1 – 8-bit problem?
>>> a = 256>>> b = 256>>> a is bTrue>>> a = 257>>> b = 257>>> a is bFalseCPython caches small integers from -5 to 256 as singletons. The same object is reused everywhere. Outside this range, new objects are created every time.
Example 2 – where did Ruby go?
>>> programming = dict()>>> programming[5.5] = "JavaScript">>> programming[5.0] = "Ruby">>> programming[5] = "Python">>> programming[5.0]'Python'5 == 5.0 is true, and both hash to the same value. Therefore, programming[5] = "Python" overwrites programming[5.0]. Ruby disappeared.
Example 3 – invalid syntax?
>>> not x == yTrue>>> y == not xSyntaxError: invalid syntaxnot is a unary operator with lower precedence than ==. not x == y is interpreted as not (x == y). But y == not x becomes syntactically incorrect – the parser expects an expression after ==, not an operator.
Example 4 – huh?
>>> a = "wtf"; b = "wtf"; a is bTrue>>> a = "wtf!"; b = "wtf!"; a is bFalseCPython interns short strings that look like identifiers. "wtf" becomes the same object. "wtf!" contains ! and is not considered an identifier – no interning, two different objects.
Conclusion
Python is full of such "gotchas" – and they are usually perfectly logical once you understand what's happening under the hood. Always use == for value comparison and is only when you truly mean the same object in memory.

Write a few lines or call directly, I'll connect you with the right specialist on the team. No pipeline nonsense, no pitch.
Related articles

Mapping 120,000 devices: how we built a network discovery platform that keeps up
How we built a network discovery platform tracking over 120,000 devices: DNS zone transfers, Temporal, SNMP templates, MongoDB, topology from MAC tables, Jaeger, and a versioned FastAPI.

From Git to VM – how we build self-service with Proxmox and Crossplane
Proxmox, Crossplane and GitOps as the foundation for self-service on your own infrastructure. Read about Petter's PoC, what works today and the next steps.

Building a Kubernetes Platform Without Vendor Lock-In
How do you build a container platform that can evolve over time? Brian Levinsen discusses solution design, OpenShift, GitOps, and minimizing vendor dependencies.


