To check if two lists are equal in Python, you can use the ==
operator or the ==
method.
In this example,
list1
and list2
with initial values.==
operator to check if list1
equals list2
.list1 = [1, 2, 3]
list2 = [1, 2, 3]
result = list1 == list2
print("Are the lists equal?", result)
Are the lists equal? True
In this example,
list1
and list2
with initial values.==
method to check if list1
equals list2
.list1 = [1, 2, 3]
list2 = [1, 2, 3]
result = list1.__eq__(list2)
print("Are the lists equal?", result)
Are the lists equal? True
In this tutorial, we learned How to check if Two Lists are Equal in Python language with well detailed examples.