Interview Prep/Python for DevOps/Language essentials & functions

What is the difference between `==` and `is`?

BeginnerConceptLanguage essentials & functions
Answer

== compares values (calls __eq__); is compares identity (same object in memory). Use is only for singletons: None, True, False, and sentinel objects. x is None is correct; x == None works but is unidiomatic and can be fooled by a custom __eq__. Never use is to compare strings or numbers, because small-int and string interning make it appear to work until it does not.

All Python for DevOps questions Roadmap: Python for automation

More on Language essentials & functions