Explanation:
๐ข Step 1: First List
[1, 2]
This list contains two integers:
1 → int
2 → int
๐ก Step 2: Second List
[1, 2.0]
This list contains:
1 → int
2.0 → float
At first glance, the lists look different because 2 and 2.0 have different types.
๐ต Step 3: Compare the First Elements
Python compares the elements position by position.
1 == 1
This is:
True
๐ Step 4: Compare the Second Elements
Now Python checks:
2 == 2.0
In Python, an integer and a floating-point number with the same numeric value compare equal:
2 == 2.0
↓
True
๐ด Step 5: Compare the Complete Lists
Both corresponding elements are equal:
[1, 2]
==
[1, 2.0]
1 == 1 → True
2 == 2.0 → True
Therefore:
[1, 2] == [1, 2.0]
returns:
True
๐ฃ Step 6: print()
The print() function displays the result:
print(True)
✅ Final Output
True

0 Comments:
Post a Comment