When you do a slicing operation e.g list[0:2]
, you essentially create a new list
Since reverse operates on the object you give it, but doesn't return anything, if you were to do print(list.reverse())
it would still print None
because reverse doesn't return anything, but modify the object you use it on.
Now, since slicing creates a new list, when you do list[0:2].reverse()
, you are modifying the list created by the slicing, which is also immediately lost since you don't assign it to any variable (and you can't since reverse doesn't return a value). Essentially, you are creating a list with the slicing, modying it, and then losing it forever
Additionally, you can assign the slicing to a variable and then use reverse on it, but it wouldn't be useful in your case
listed= ["a", "b", "c", "d", "e", "f"]
sliced = listed[0:2]
sliced.reverse()
print(sliced) prints ['b', 'a']
Hope this is clear
(Last advice, don't call your list "list
", it shadows the built-in name)