Python Error: unsupported operand type(s) for +: int and NoneType

Python Error: unsupported operand type(s) for +: int and NoneType

When none of the if test in number_translator() evaluate to true, the function returns None. The error message is the consequence of that.

Whenever you see an error that include NoneType that means that you have an operand or an object that is None when you were expecting something else.

In your giant elif chain, you skipped 13. You might want to throw an error if you hit the end of the chain without returning anything, to catch numbers you missed and incorrect calls of the function:

...
elif x == 90:
    return 6
else:
    raise ValueError(x)

Python Error: unsupported operand type(s) for +: int and NoneType

I got a similar error with / operand while processing images. I discovered the folder included a text file created by the XnView image viewer. So, this kind of error occurs when some object is not the kind of object expected.

Leave a Reply

Your email address will not be published. Required fields are marked *