#python – ValueError: invalid literal for int() with base 10
Explore tagged Tumblr posts
techhelpnotes · 3 years ago
Text
python – ValueError: invalid literal for int() with base 10
>>> int(55063.000000) Traceback (most recent call last):  File <stdin>, line 1, in <module> ValueError: invalid literal for int() with base 10: 55063.000000
Got me here…
>>> int(float(55063.000000)) 55063
Has to be used!
The following are totally acceptable in python:
passing a string representation of an integer into int
passing a string representation of a float into float
passing a string representation of an integer into float
passing a float into int
passing an integer into float
But you get a ValueError if you pass a string representation of a float into int, or a string representation of anything but an integer (including empty string). If you do want to pass a string representation of a float to an int, as @katyhuff points out above, you can convert to a float first, then to an integer:
>>> int(5)
0 notes
splicejunction · 5 years ago
Text
JUST HAD ANOTHER MOMENT
>be me >trying to convert a string into a number. the string input is 2.5E-06 (which is 2.5x10^-6 in scientific notation). the reason to do this is because you can’t do math on strings. python treats them as words unless you convert them to numbers >function int() converts string to integer >for example if you type in “4″ as a string it will convert it to the integer 4 so that you can do math on it >>>cT = int(2.5E-06) >get “ValueError: invalid literal for int() with base 10″ >spend 3 minutes going Huh????????? >realize I cannot convert 2.5E-06 to an integer because decimals are not integers >owned by basic math once again
Just had the most epic python fail moment of my life
4 notes · View notes