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
So we would say that Python doesn't have an exact equivalent to the JavaScript ==
or ===
operators. The way Python uses ==
, without a ===
operator, is the norm. JavaScript (and PHP) are a bit unusual.
This last bit about bool
might be a bit surprising, but bool
is a subclass of int
in Python.
Closest would maybe be the is
operator. It returns True
only if both variables point to the same object.