|
|
|
|
|
by kgm
2208 days ago
|
|
Though "when" the object is created isn't always so straightforward: >>> x = 257
>>> y = 257
>>> x is y
False
>>> def f():
... x = 257
... y = 257
... return x is y
...
>>> f()
True
The lesson being that `is` is essentially meaningless for immutable objects, and to always use `==`. |
|
OTOH it’s recommended to use `is` rather than `==` when comparing to “singletons like `None`”.
https://www.python.org/dev/peps/pep-0008/#programming-recomm...