ValueError – invalid literal for int() with base 10 Python

Last Updated On Sunday 19th Dec 2021

invalid literal for int() with base 10

Properties of Integers

  • Integer data types are whole numbers.
  • They Can be range between -2,147,483,647 to 2,147,483,647.
  • Can’t have fractions,decimals or percentages with integers.
  • Putting quotes around a value allows them to convert to integer,only if they are whole number.
	data = int(2.2)
print(data) // 2
	

In Above Example

  • program round integers to down.
  • 2.2 also recognize also an integer
	data = int('2.2')
print(data)
	

The above code returns the following

valueerror: invalid literal for int() with base 10: “

	ValueError: invalid literal for int() with base 10:
	

Make Sure input don’t have an any decimal places or fractions or percentages

  • You can convert to a float first, then to an int
	data = int(float('4.6'))
print(data) // 4
	
	data = float('4.6')
print(data) // 4.6