Confusion between equality ==
, !=
and identity is
in conditional expressions can lead to unintended behavior.
1def notequals_operator_noncompliant():
2 phrase = "Thisisstring"
3 # Noncompliant: uses checks for equality instead of identity.
4 if phrase != None:
5 print(True)
1def isnot_operator_compliant():
2 phrase = "Thisisstring"
3 # Compliant: uses the correct mechanism for checking the identity.
4 if phrase is not None:
5 print(True)