3 ms·
== is most funny operator of all time. My prefered: .1 + .2 == .3 \\false [] == false \\true but {} == true \\false
by dehef 9y ago
== is most funny operator of all time. My prefered:
.1 + .2 == .3 \\false
[] == false \\true
but {} == true \\false
- Doxin 9y agoAll of those have a sane reasoning though. 0.1+0.2 is in fact, not equal to 0.3. it is equal to 0.30000000000000004. Floating point numbers aren't exact and you shouldn't expect them to be. When comparing things to a boolean that thing gets cast to a boolean. This is by design. bool([]) evaluates to False, so obviously False==False returns True. Same goes for your last example, bool({}) evaluates to False, after which False==True obviously returns False. Now whether or not you like the way those works, that's how it works by design and is hardly unexpected, except if you're unfamiliar with the language.
- BrandoElFollito 9y ago> that's how it works by design and is hardly unexpected Not only that but also very useful (checking if a list a is not empty is easy to read for instance (if a:...)) Well except the first example which is an annoying fact of life.