我正在尝试编写一个程序来比较两个列表,如果它们都具有相同的变量,则返回“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)
为什么会发生这种情况?