Because in Python (at least in 2.x, since I do not use Python 3.x), int() behaves differently in strings and numerical values. If you enter a string, then python will try to parse it based on 10 int
int ("077") >> 77
But if you enter a valid numeric value, then python will interpret it according to its base and type and convert it to base 10 int.
int (077)
So int('1e1') will try to 1e1 as the base string of 10 and throw a ValueError . But 1e1 is a numerical value (mathematical expression):
1e1 >> 10.0
So, int will process it as a numeric value and process it as if converting it to float(10.0) , and then parse it into int.
Thus, by calling int() with a string value, you must be sure that the string is a valid integer value.
source share