Explanation:
๐น Step 1: Create List
x = [1,2]
A list x is created containing:
[1,2]
๐น Step 2: Execute x.clear()
x.clear()
๐งฉ What clear() Does
Removes ALL elements from list
Modifies original list directly
So:
[1,2] → []
๐น Step 3: Important Twist ๐
Most people think:
clear() returns []
BUT ❌
clear() returns:
None
Because:
It modifies list in-place
Does NOT create new list
๐น Step 4: Execute print()
print(x.clear())
Since:
x.clear() → None
Python prints:
None
๐ฅ Final Output
None

0 Comments:
Post a Comment