小编use*_*791的帖子

比较两个列表会返回 True,即使需要返回 False

我正在尝试编写一个程序来比较两个列表,如果它们都具有相同的变量,则返回“True”,否则返回“False”。

代码是:

def are_lists_equall(list1, list2):
    if len(list1) == len(list2) and list1.sort() == list2.sort():
        return True
    else:
        return False

list1 = [0.6, 1, 2, 3]
list2 = [9, 0, 5, 10.5]
print(are_lists_equall(list1, list2))
Run Code Online (Sandbox Code Playgroud)

输出是:

True
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况?

python syntax-error

0
推荐指数
1
解决办法
713
查看次数

标签 统计

python ×1

syntax-error ×1