Python error TypeError: 'NoneType' object is not iterable solution

  • 2020-05-24 05:43:32
  • OfStack

Python error TypeError: 'NoneType' object is not iterable solution

TypeError: 'NoneType' object is not iterable this error tip 1 usually occurs when None is assigned to multiple values.


def myprocess():  
  a == b     
  if a != b:                      
    return True, value; 
flag, val = myprocess()  

In the judgment statement, when the if condition is not met and there is no else statement, the function returns None by default.

When there is no return statement, Python also returns None by default

When called, when you assign None to multiple values, you will be prompted: TypeError: 'NoneType' object is not iterable

In this case, both flag and val are given None(None is returned by default because the if condition is not met) and this error occurs.

So the return value of 1 must take into account the coverage of the conditional branch

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: