AttributeError: 'NoneType' object has no attribute 'extend'

Python使用中可能遇到的小问题

AttributeError: 'NoneType' object has no attribute 'extend' 或者AttributeError: 'NoneType' object has no attribute 'append'

原因:这两种方法都是没有返回值的,也就是返回的是NoneType类型,而NoneType数据再次调用extend或者append方法时就会报上面的error。

# 错误写法:将extend的返回值赋值给aa,导致aa此时成为NoneType类型

 # 正确写法:直接使用,不用返回值

原文地址:https://www.cnblogs.com/qi-yuan-008/p/11753247.html