I tried to do this but fail:
File "<input>", line 1
1==='1'
^
SyntaxError: invalid syntax
Is there any workaround?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With