Reverse the order of elements in a list in Python
When we need to reverse all the elements in a list, we use the reverse
method. We don't specify anything in its parameter:
lst = [1, 2, 3]
lst.reverse()
print(lst) # [3, 2, 1]
The following code is given:
lst = ['a', 'b', 'c', 'd']
lst.reverse()
print(lst)
Tell me what will be output to the console.
The following code is given:
lst = [10, 4, 8, 2]
lst.reverse()
print(lst)
Tell me what will be output to the console.