0

The comparison operator is doesn't work. I don't understand why both variables have the same ID.

enter image description here

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
  • 4
    Please post your code as text, no screenshots. – Klaus D. Jul 18 '21 at 17:23
  • 1
    Unfortunately, the linked question doesn't really answer your question. When you create integers, you get a new object even though they are the same value. `is` is `False` because they are two separate 500 objects. Except sometimes python reuses the same object. Integers are immutable so its safe. When python compiles a .py file, it keeps track of integers its already created and reuses them. That's what happened in `%Run`. And python also caches integers from, um I think -4 to 255, so `is` will be True. – tdelaney Jul 18 '21 at 17:32
  • 2
    BUT, never depend on that. Use `==` instead of `is` for integers. – tdelaney Jul 18 '21 at 17:32

0 Answers0