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

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

Python throws error ValueError: invalid literal for int() with base 10: '' when float string is passed to int() function.

Python throws the error, ValueError: invalid literal for int() with base 10:”, when you pass a float string in int() function. Although, you can pass the string in float() function.

Consider this example –

>>> int('5555.00')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '5555.00'

PythonCopy

The problem with this code is that you are passing a float string '5555.00' in int() function. The correct way of doing this is to first convert it into float() and then into int().

python error python error python-short

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

'method' Object Is Not Subscriptable - Python Error

Python throws error 'method' object is not subscriptable when a class method is indexed with [] like it its a list or array.

'function' Object Is Not Subscriptable - Python Error

Python throws error, 'function' object is not subscriptable, when we try to index or subscript a function. Lear from code and demo.

'float' Object Is Not Iterable - Python Error

Python throws error, 'float' object is not iterable, when you try to loop over a float value. Floats are not an iterable object.

‘dict’ Object Has No Attribute ‘iteritems’, ‘iterkeys’ Or ‘itervalues’ – Python Error

Python throws error, ‘dict’ object has no attribute ‘iteritems’, because `iteritems()` function is removed from Python 3\. Similarly, functions like `iterkeys()` and `itervalues()` are also removed. According to [Python3.0 Built-in changes...

Python Tricks Every Developer Should Know

In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.