相关疑难解决方法(0)

在Python中正确使用list.append

想知道为什么方法1是正确的,方法2是错误的.

方法一:

def remove_duplicates(x):
    y = []
    for n in x:
        if n not in y:
            y.append(n)
    return y
Run Code Online (Sandbox Code Playgroud)

方法2:

def remove_duplicates(x):
    y = []
    for n in x:
        if n not in y:
            y = y.append(n)
    return y
Run Code Online (Sandbox Code Playgroud)

我不明白为什么第二种方法会返回错误的答案?

python

4
推荐指数
1
解决办法
167
查看次数

标签 统计

python ×1