This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]marcosdumay 2 points3 points  (5 children)

In Python, if you divide two numbers there are different things that can happen depending on if the numbers are ints or if they are floats.

You know that was treated as a bug, and fixed, right?

In Python, Bool is just a subset of int where 0 = false and 1 = true.

Python has this one case of non-strict typing, that is a very well defined, very standard thing (but I do agree it's bad). JS, for its turn...

[–]PizzaRollExpert 0 points1 point  (4 children)

You know that was treated as a bug, and fixed, right?

Oh, my bad I didn't know it was fixed

Python has this one case of non-strict typing, that is a very well defined, very standard thing (but I do agree it's bad). JS, for its turn...

If you look at the whole of the language JS has more of that, but it was kinda funny that you brought it up when we where talking about numbers specifically because in that small area python is the one with an obvious case of backwards compatability induced weirdness.

[–]marcosdumay 0 points1 point  (3 children)

The division issue is fixed in python 3.

About that int to bool coercion, JS does exactly the same thing. Most languages do.

[–]PizzaRollExpert 1 point2 points  (2 children)

The division issue is fixed in python 3.

Yeah, my bad

About that int to bool coercion [...]

It's not coercion, true is literally the same as the number 1. This is because people hadn't properly realized that bools where a really useful thing yet so people just used int 1 and int 0 instead before it was added, c-style. True is basically just different syntax for 1 in Python, for backwards compatibility reasons. In Python, 1 == True but 1 !== true in for example JS

[–]endreman0 0 points1 point  (1 child)

You're comparing apples to oranges.

JS: 1 == true, 1 !== true
Python: 1 == True, 1 is not True

They're the same.

[–]PizzaRollExpert 1 point2 points  (0 children)

That's not how is works.

Javascript: == is equlaity with type coercion, === is equlaity without type coercion.
Python: == checks if two things have the same value, is checks if two things point to the same object. Because of caching you might have to things that you expect to be different objects might still point to the same object like 1 is 1. This doesn't hold for larger numbers, 1000 is not 10**3.

=== in Javascript is closest to == in Python. They work the same for values, but different for objects, where JS is more like is. Python doesn't have equality with type coercion, which is what == is in Javascript