Code -
a = [1, 2, 3, 4, 5]
print(a[:4].pop())
Detailed Solution -
This code will print 4. Here's what happens:
a[:4] creates a new list slice containing the elements [1, 2, 3, 4].
Then, pop() is called on this new list slice, which removes and returns the last element of the slice, which is 4.
The print() function then displays the value returned by pop(), which is 4.
0 Comments:
Post a Comment