Programmers learn & share
0 votes
814 views

Problem :

I am facing the issue in passing a function as a parameter to another function as follows

typeerror: int() argument must be a string, a bytes-like object or a number, not 'nonetype'

by (6.9k points)   | 814 views

1 Answer

0 votes

Solution :

The error is telling you that you can not convert an entire list into an integer. The better way to do it is to get an index from the list and convert that into an integer as follows:

x = ["0", "1", "2"] 
y = int(x[0]) # here accessing the zeroth element

If you want to convert a whole list into an integer then you need to convert the list into a string first as follows:

x = ["0", "1", "2"]
y = ''.join(x) #converting the list into string
z = int(y)

And if your list elements are not strings then you need to convert them to strings before using str.join as follows:

x = [0, 1, 2]
y = ''.join(map(str, x))
z = int(y)

Please make sure that you are not returning a nested list.

by (36.1k points)  
2,227 questions
2,734 answers
59 comments
241 users