'NoneType'对象没有属性'append' python

Jun*_*Liu 1 python

我运行以下代码:

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()
Run Code Online (Sandbox Code Playgroud)

但出现以下错误:

d=d.append(i)  
AttributeError: 'NoneType' object has no attribute 'append' 
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况?请帮忙修复它。

Reb*_*que 7

d.append(i)None
因此返回:
d = d.append(i)分配Noned

将该行替换为:
d.append(i)

同样适用于c = c.append(i)