Friday, 29 December 2023

python == operator instead of ===, ! operator

 https://stackoverflow.com/questions/44425359/is-there-any-python-operator-that-equivalent-to-javascript-triple-equal

The ordinary == operator in Python already works much like the === operator in JavaScript, in that it won't do string conversions. However, it does not compare types.

>>> 1 == '1'
False
>>> 1 == 1.0
True
>>> 1 == True
True
There is also no ! operator, just use if a == False

No comments:

Post a Comment