Very interesting and kinda cool fact for Python heads / beginners out there - operator 'is' compares memory reference for objects, so it is useful check if it is same object you check. '==' will check actual values. Nice thing to know. #Python #programming #beginner #learningprogramming
@peteriskrisjanis it's a common source of bug, people will use "is" to compare values (strings or integers), and it'll sometimes work, especially for short strings, small numbers, or in the repl, but it will break in unpredictable ways in production.
Only use "is" when you mean "the same object", and you are sure it's not a copy.
It's ok for "is None" or "is True/False" of which you know there is only one copy.
@tshirtman yeah, in my use case I needed exactly to compare same objects with same memory address (just having bunch of those referenced in different places) so it was exactly what I was looking for, but I have made that mistake with using it with numbers or strings 😅