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

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

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

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

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

 

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

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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-25
  • 2021-06-13
  • 2022-01-08
  • 2021-11-20
  • 2021-07-31
  • 2022-01-29
  • 2022-12-23
相关资源
相似解决方案