Explanation:
๐น Line 1: Create the First Set
{1}
Python creates a set containing one element.
Current Set:
{1}
Memory:
Set A
{1}
๐น Line 2: Create the Second Set
{1, 2}
Python creates another set containing two unique elements.
Current Set:
{1, 2}
Memory:
Set B
{1, 2}
๐น Line 3: Compare Using <
{1} < {1, 2}
This is the biggest trick.
Most developers think:
"< compares numbers."
❌ Wrong!
For sets, the < operator does not compare values numerically.
Instead, it checks whether the left set is a proper subset of the right set.
Meaning:
"Are all elements of the left set present in the right set, and does the right set have at least one extra element?"
๐น Step 1: Check Every Element
Python checks whether every element in:
{1}
exists inside:
{1, 2}
Check:
1 ✓ Found
All elements are present.
๐น Step 2: Is It a Proper Subset?
Now Python checks whether the right set has more elements.
Left Set
{1}
↓
1 Element
-------------------
Right Set
{1,2}
↓
2 Elements
Since:
Every element of the left set exists in the right set ✅
The right set contains an extra element (2) ✅
It is a proper subset.
Result:
True
๐น Step 3: Execute print()
Python now executes:
print(True)
Output:
True

0 Comments:
Post a Comment