Ever got this python error? invalid literal for int with base 10 Or some sort of this same message? Keep reading to know the solution for this Python error and to master the data types conversions.
Python Error: Invalid Literal for Int with Base 10
In this post, I will explain the solution for the “invalid literal for int” errors on Python. We all know that with python is very handy when converting between different data types easily. From strings to integers, from integers to floats, passing a string to float…
But, what if you want to convert from a string representing a float to an integer?
Well, then python will raise an error saying it can’t! See the example below:
# String with some numbers (float) strval = "152.569" intval = int(strval) # Output: Traceback (most recent call last): File "main.py", line 3, in <module> intval = int(strval) ValueError: invalid literal for int() with base 10: '152.569'