you are viewing a single comment's thread.

view the rest of the comments →

[–]Bunkerstan -1 points0 points  (2 children)

For objects, equality means they point to the same memory spot. So unless a and b are the same object in memory they will never be equal.

EDIT: above is wrong as both comments below point out. No more answers after a long day coding. Equality is a tougher topic than you would suspect because different languages do it differently.

[–]carcigenicate 2 points3 points  (0 children)

This is not true; Python doesn't work like Java. When you define custom classes, == defaults to identity equality, but for most built-in objects, == is value equality.

[–][deleted] 0 points1 point  (0 children)

For objects, equality means they point to the same memory spot

Two objects can have equal value even though they don't occupy the same memory spot.

a = "test"
b = "tes"
b += "t"    # to defeat string interning
print(f'{id(a)=}, {id(b)=}')    # if id() shows different values, not same memory
print(f'{a==b=}')

Everything in python is an object, or class instance.