Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

The == Operator

Zarata on Aug. 11, 2020

It’s slightly “disturbing” that despite the SyntaxWarning for 44 is 11 * 4 the REPL still returns True. This return muddies the point you are making. What is the meaning of the True return in this case? (For that matter, why is this flagged as a Warning and not an out-and-out Error?)

Liam Pulsifer RP Team on Aug. 11, 2020

Hmmm, I see where the disturbance comes from @Zarata, but I think a return value of True is still the best possible option here. The is operator answers a very simple question in Python – do the two operands have the same id value? In this case, they do because of the interning system that Python puts in place, so the expression returns True. The reason that it’s a warning is because while it’s a logically consistent result, it’s not clear why anyone would want to use it. An error would imply that the is comparator can’t be applied to these two operands for some reason, when in this case that’s not really true. Of course, reasonable people can disagree on this, so if you were to implement your own programming language, it would be perfectly reasonable to make this kind of thing a SyntaxError. I think though that this fits under Python’s relatively permissive approach to operations in general: Python tries not to explicitly prohibit you from doing things unless it would cause a direct error or impossible result.

Zarata on Aug. 11, 2020

I guess I’m not Dutch :)

Become a Member to join the conversation.