-1

I'm curious about the behavior of the following code:

0.0 is 0.0 # True

a = 0.0
a is 0.0 # False

It seems to me that a is 0.0 should evaluate to True. In my particular case I need to distinguish when a variable is 0.0 specifically, so a == 0 will not work because it will fail when a is equal to False. What's the best way to accomplish this?

hoffee
  • 470
  • 3
  • 16
  • Does this answer your question? [How is the 'is' keyword implemented in Python?](https://stackoverflow.com/questions/2987958/how-is-the-is-keyword-implemented-in-python) – Josh Clark Apr 16 '20 at 16:03
  • I think I understand `is` (checks identity rather than equality), but this doesn't explain how to check for that `a` is specifically 0.0 and not False. – hoffee Apr 16 '20 at 16:12

1 Answers1

0

The == operator is used when the values of two operands are equal, then the condition becomes true.

The is operator evaluates to true if the variables on either side of the operator point to the same object and false otherwise.