What is a 'NoneType' object?

前端 未结 9 1405
南笙
南笙 2020-11-28 03:12

I\'m getting this error when I run my python script:

TypeError: cannot concatenate \'str\' and \'NoneType\' objects

I\'m pretty sure the \'

9条回答
  •  臣服心动
    2020-11-28 03:43

    In the error message, instead of telling you that you can't concatenate two objects by showing their values (a string and None in this example), the Python interpreter tells you this by showing the types of the objects that you tried to concatenate. The type of every string is str while the type of the single None instance is called NoneType.

    You normally do not need to concern yourself with NoneType, but in this example it is necessary to know that type(None) == NoneType.

提交回复
热议问题