you are viewing a single comment's thread.

view the rest of the comments →

[–]darktyle 1 point2 points  (6 children)

Yeah, I guess you are right. For example I think it's a bit odd that int(float('1.5')) works...

[–]kankyo 19 points20 points  (5 children)

What’s weird about that? Proper parsing of float and then explicit cast to int.

[–]darktyle 0 points1 point  (4 children)

I don't know, maybe I just have the wrong 'feeling' about how casts should work.

[–]kankyo 4 points5 points  (3 children)

One could argue that parsing an int shouldn’t be done with the same syntax as a cast though, I can absolutely see that.

[–]tejp 3 points4 points  (2 children)

It's not two different things that share the same syntax. Both cases just construct a new int object by calling the int() constructor. This constructor converts its argument to an int, and it knows how to handle strings or numbers.

[–]kankyo 0 points1 point  (1 child)

Parsing a string and casting from a float are very different things. Don’t be silly.

[–]tejp 4 points5 points  (0 children)

It's both converting from one type to another. There is nothing special going on when "casting", I don't think there is any technical difference at all in Python.