Re:What the f*ck python
by astrobe_ on Thursday August 31, 2017 @01:03PM
(#15141783)
Language inconsistencies and questionable decisions is why I use my own language whenever I can. When something is wrong, I just fix it. The end result is that it is therefore ugly, stupid and mean for everyone else though.
Re:What the f*ck python
by Doxin on Friday September 01, 2017 @06:20AM
(#15147296)
All 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.
Unless they grabbed that from another language as well. And that all being said, the equivalence table for JavaScript is crazy.
- Matz, the inventor of Ruby
.1 + .2 == .3 \\false
[] == false \\true
but {} == true \\false
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.
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.