What will be the output of the following Python code snippet? [code]a=[1, 4, 3, 5, 2] b=[3, 1, 5, 2, 4] a==b set(a)==set(b)[/code]

What will be the output of the following Python code snippet?
Code:
a=[1, 4, 3, 5, 2]
b=[3, 1, 5, 2, 4]
a==b
set(a)==set(b)
A.
True
False
B.
False
False
C.
False
True
D.
True
True
 
Answer: c
Explanation: In the code shown above, when we check the equality of the two lists, a and b, we get the output false. This is because of the difference in the order of elements of the two lists. However, when these lists are converted to sets and checked for equality, the output is true. This is known as order-neutral equality. Two sets are said to be equal if and only if they contain exactly the same elements, regardless of order.
 

Tìm kiếm

Back
Top