我运行以下代码:
import sys
def find_common(a,b,c):
d=[]
for i in a:
if i in b:
d=d.append(i)
for i in d:
if i not in c:
c=c.append(i)
print(c)
return c
if __name__ == '__main__':
a=[1,1,2,4]
b=[2,2,3,4]
c=[]
find_common(a,b,c)
sys.exit()
但出现以下错误:
d=d.append(i)
AttributeError: 'NoneType' object has no attribute 'append'
为什么会这样?请帮助修复它。
最佳答案
d.append(i)
返回 None
因此:
d = d.append(i)
将 None
分配给 d
将该行替换为:
d.append(i)
c = c.append(i)
也是如此
关于python - 'NoneType' 对象没有属性 'append' python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46578288/