What's the difference of != and is not

(this question is a pure Python question, please let me know if it’s not appropriate to this place)

I have a list of tuples, each of them is (surface, tag). The tag is a simple string either “A” or “B”
I have a code
if tag is not “B”:
do something
do the other thing.
This can pick up roughly 60 percent of surface "A"s, but the rest of 40 percent weave through the condition statement.
Now I tried
if tag != “B”:
do something
do the other thing.
This worked.
What’s the difference of these two exactly?


Hi @mikity_kogekoge,

Basically, is compares object reference, and == compares object value equality.

a = 3424
b = 3424
print a is b # False
print a == b # True

– Dale

Thanks Dale, I see, and I believe I know what object references are.

The attached has a Python script that generates bunch of “A” and compares with another “A” using “is not”. It says two "A"s are same at some probability… THis is funny…
python compare.gh (6.7 KB)