小编给大家分享一下python判断两个列表是否相同的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

判断两个列表是否相同,在Python2中可以使用cmp()函数,但是在Python3中我们可以使用下面的方法来比较两个list是否相等

importoperatora=[1,-1,0]b=[1,-1,0]c=[-1,1,0]print(operator.eq(a,b))print(operator.eq(a,c))

实验结果:

D:\pycharmprogram\leetcode\venv\Scripts\python.exeD:/pycharmprogram/leetcode/3Sum/operator_test.pyTrueFalseProcessfinishedwithexitcode0

分析:

两个列表必须完全相同(包括位置),只有这样才能是True。

看完了这篇文章,相信你对python判断两个列表是否相同的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!