leetcode刷题--TypeError:object of type 'NoneType' has no len()/AttributeError: 'NoneType' object has no attribute 'append'

错误:

一.TypeError:object of type 'NoneType' has no len()

 list=[]
 i=0
 j=0
 while len(list)<=len(nums1)+len(nums2):

报错:TypeError:object of type 'NoneType' has no len()

原因:此时的list是空列表,它的类型是None而不是list,这时候可以改为

while list==None or len(list)<=len(nums1)+len(nums2):

二.AttributeError: 'NoneType' object has no attribute 'append'

nums=nums.append('a')

报错:AttributeError: 'NoneType' object has no attribute 'append'

原因:append()函数没有返回值,不需要再赋给nums,应改为:

nums.append('a')
print(nums)

 

posted @ 2023-03-20 14:09  三二幺  阅读(462)  评论(0)    收藏  举报