小编Jun*_*Liu的帖子

'NoneType'对象没有属性'append' 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)

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

python

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1