Explanation:
1. Create the List
x = [3, 1, 2]
A list named x is created with three numbers:
3, 1, 2
So initially:
x = [3, 1, 2]
2. Apply the sort() Method
y = x.sort()
The sort() method sorts the original list in ascending order.
So x changes from:
[3, 1, 2]
to:
[1, 2, 3]
However, an important point is that sort() does not return the sorted list.
It returns:
None
Therefore:
x = [1, 2, 3]
y = None
3. Print y
print(y)
Since y contains the return value of x.sort(), and sort() returns None, Python prints:
None
✅ Final Output
None

0 Comments:
Post a Comment