close

[Solved] Type: argument of type ‘NoneType’ is not iterable

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Type: argument of type ‘NoneType’ is not iterable 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 Type: argument of type ‘NoneType’ is not iterable Error Occurs?

Today I get the following error Type: argument of type ‘NoneType’ is not iterable in python.

How To Solve Type: argument of type ‘NoneType’ is not iterable Error ?

  1. How To Solve Type: argument of type 'NoneType' is not iterable Error ?

    To Solve Type: argument of type 'NoneType' is not iterable Error If you print wordInput before the offending line, you will see that wordInput is None.

  2. Type: argument of type 'NoneType' is not iterable

    To Solve Type: argument of type 'NoneType' is not iterable Error If you print wordInput before the offending line, you will see that wordInput is None.

Solution 1


If a function does not return anything, e.g.:

def test():
    pass

it has an implicit return value of None.

Thus, as your pick* methods do not return anything, e.g.:

def pickEasy():
    word = random.choice(easyWords)
    word = str(word)
    for i in range(1, len(word) + 1):
        wordCount.append("_")

the lines that call them, e.g.:

word = pickEasy()

set word to None, so wordInput in getInput is None. This means that:

if guess in wordInput:

is the equivalent of:

if guess in None:

and None is an instance of NoneType which does not provide iterator/iteration functionality, so you get that type error.

The fix is to add the return type:

def pickEasy():
    word = random.choice(easyWords)
    word = str(word)
    for i in range(1, len(word) + 1):
        wordCount.append("_")
    return word

Solution 2


The python error says that wordInput is not an iterable -> it is of NoneType.

If you print wordInput before the offending line, you will see that wordInput is None.

Since wordInput is None, that means that the argument passed to the function is also None. In this case word. You assign the result of pickEasy to word.

The problem is that your pickEasy function does not return anything. In Python, a method that didn’t return anything returns a NoneType.

I think you wanted to return a word, so this will suffice:

def pickEasy():
    word = random.choice(easyWords)
    word = str(word)
    for i in range(1, len(word) + 1):
        wordCount.append("_")
    return word

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