close

[Solved] TypeError: float() argument must be a string or a number, not ‘list’ python

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: float() argument must be a string or a number, not ‘list’ python in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: float() argument must be a string or a number, not ‘list’ python Error Occurs?

Today I get the following error TypeError: float() argument must be a string or a number, not ‘list’ python in python.

How To Solve TypeError: float() argument must be a string or a number, not ‘list’ python Error ?

  1. How To Solve TypeError: float() argument must be a string or a number, not 'list' python Error ?

    To Solve TypeError: float() argument must be a string or a number, not 'list' python Error You can't call float on a list directly. You can use map to call float on each item in the list. Like so:

  2. TypeError: float() argument must be a string or a number, not 'list' python

    To Solve TypeError: float() argument must be a string or a number, not 'list' python Error You can't call float on a list directly. You can use map to call float on each item in the list. Like so:

Solution 1

You can’t call float on a list directly. You can use map to call float on each item in the list. Like so:

b = map(float, a[0].split("*"))

In python 3.x

b = list(map(float, a[0].split("*")))

Or for more readability, use a list comprehension. Works for both python2 and python3:

b = [float(s) for s in a[0].split("*")]

But be sure the items after splitting are floatable

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read