Sep-12-2021, 04:50 PM
==
when comparing values and is
when comparing identities(which is object's memory address).Can use
id()
to see this.>>> a = "this is test string" >>> b = "this is test string" >>> id(a) 2777033042000 >>> id(b) 2777033041840 >>> a is b False >>> help(id) Help on built-in function id in module builtins: id(obj, /) Return the identity of an object. This is guaranteed to be unique among simultaneously existing objects. (CPython uses the object's memory address.)So there is underlaying stuff going on eg -5 to 256 most used numbers has a optimization to cache these in same place in memory.
>>> c = 50 >>> d = 50 >>> c is d True >>> c = 257 >>> d = 257 >>> c is d False