x == y
This expression evaluates if x
and y
are the same value and returns the result as a boolean value. Generally both type and value need to match, so the int 12
is not the same as the string '12'
.
12 == 12
# True
12 == 1
# False
'12' == '12'
# True
'spam' == 'spam'
# True
'spam' == 'spam '
# False
'12' == 12
# False
Note that each type has to define a function that will be used to evaluate if two values are the same. For builtin types these functions behave as you'd expect, and just evaluate things based on being the same value. However custom types could define equality testing as whatever they'd like, including always returning True
or always returning False
.