Why isn't it possible to directly convert a floating point number represented as a string in Python to an int variable?
Traceback (most recent call last):
File "<stdin>", line 1, in
ValueError: invalid literal for int() with base 10: '10.2'
The reason is that
int is doing two different things in your two examples.
In your first example,
int is converting a string to an integer. When you give it
10.2, that is not an integer so it fails.
In your second example,
int is casting a floating point value to an integer. This is defined to truncate any fractional part before returning the integer value.