Comparison in Python

Python has two comparison functions:

a == b a is b

However, they are not the same.

tests object equivalence, and is equivalent to  or.

tests object equivalence, and is equivalent to.

Caveat
You are recommended to use. In particular, you should never use  for string comparison. The reason is that Python employs string caching, which behaves differently for different lengths of strings, or whether you are running Python in interactive mode or not. For example, the following code resulted in False in interactive mode, but in True in non-interactive mode on my computer:

a = "some string" b = "some string" print (a is b)  # Bad practice, use a == b instead!