Equal To

suggest change
x == y

This expression evaluates whether x and y are equal and returns a boolean. The int 12 is not equal to the string '12'. Numbers are an exception: 1 == 1.0 and True == 1 are both true.

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents