Skip to content

Do not compare strings using "is"

Michiel Cottaar requested to merge syntax-warnings into master

It is a bad idea to do any comparisons in python using is instead of ==, unless you are sure you know what you are doing is correct. The reason for that is that the former compares the identity of the object (which you usually do not want), while the latter compares the value. For an example of the confusing behaviour of comparison using is when comparing strings:

>>> a =  "hello"
>>> a is "hello"
True
>>> a =  "hello!"
>>> a is "hello!"
False
Edited by Michiel Cottaar

Merge request reports