Python Forum
ValueError: invalid literal for int() with base 10:
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: invalid literal for int() with base 10:
#6
(Jun-10-2020, 07:59 PM)omega_elite Wrote: ValueError: invalid literal for int() with base 10

The error message invalid literal for int() with base 10 would seem to indicate that you are passing a string that's not an integer to the int() function . In other words it's either empty, or has a character in it other than a digit. You can solve this error by using Python isdigit() method to check whether the value is number or not. The returns True if all the characters are digits, otherwise False . The other way to overcome this issue is to wrap your code inside a Python try...except block to handle this error.

Sometimes the difference between Python2.x and Python3.x that leads to this ValueError: invalid literal for int() with base 10 . With Python2.x , int(str(3/2)) gives you "1". With Python3.x , the same gives you ("1.5"): ValueError: invalid literal for int() with base 10: "1.5".
Reply


Messages In This Thread
RE: ValueError: invalid literal for int() with base 10: - by delonbest - Dec-30-2020, 06:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  invalid literal for int() with base 10: '# NRECS: 1096\n' Baloch 8 4,716 May-24-2020, 02:08 AM
Last Post: Larz60+
  invalid literal for int() with base 10: '' mrsenorchuck 5 5,818 Apr-29-2020, 05:48 AM
Last Post: markfilan
  ValueError: invalid literal for int() with base 10: '\n' srisrinu 9 5,953 Apr-13-2020, 01:30 PM
Last Post: ibreeden
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 7,004 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  input-ValueError: invalid literal for int() jacklee26 2 2,630 Feb-21-2020, 01:27 PM
Last Post: ndc85430
  ValueError: invalid literal for int() with base 10: '0.5' emmapaw24 2 3,817 Feb-16-2020, 07:24 PM
Last Post: emmapaw24
  ValueError: invalid literal for int() with base 10: '' Jay123 7 7,467 Aug-05-2019, 02:43 PM
Last Post: Jay123
  ValueError: invalid rectstyle object fen1c5 1 5,795 Jun-05-2019, 02:51 PM
Last Post: heiner55
  ValueError: invalid literal for int() with base 10: '' ivinjjunior 6 9,276 Apr-20-2019, 05:37 PM
Last Post: keames
  Problem with "invalid literal for int() with base 10: '' jirkaj4 4 10,550 Jan-23-2018, 06:55 PM
Last Post: jirkaj4

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020