Python问题:'Nonetype' object is not iterable

[A]

This error generally occurs when None assigned to multiple values.

 

[Case]

It defines the following function

Copy the code
def test():
       if value == 1:
              a = b = 1
              return a,b value = 0 a,b = test()
Copy the code

The implementation of this test program will complain: "TypeError: 'NoneType' object is not iterable"

This is without taking into account the circumstances else, when if condition is not satisfied, the function returns the default None.

When you call, the None assigned to a, b

It is equivalent to a, b = None

There have been such a mistake.

 

【in conclusion】

1. None will be assigned to more than one value, there will be prompt: TypeError: 'NoneType' object is not iterable

2. The function returns the value to the cover must consider the conditional branch

3. In the absence of a return statement, python default will return None

Knowledge to share with everyone, but to bring the original link is respect for the author.

Guess you like

Origin www.cnblogs.com/classics/p/11165596.html