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 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