belongs to collection: Python List Exercises
Given:
list1 = [100, 200, 300, 400, 500]
Expected output:
[500, 400, 300, 200, 100]
Hint:
Use the list function reverse()
reverse()
Solution1:list function reverse()
list1 = [100, 200, 300, 400, 500] list1.reverse() print(list1)
Solution2:Using negative slicing
-1 indicates to start from the last item.
list1 = [100, 200, 300, 400, 500] list1 = list1[::-1] print(list1)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
Use the list function
reverse()
Solution1:list function
reverse()
Solution2:Using negative slicing
-1 indicates to start from the last item.
need an explanation for this answer? contact us directly to get an explanation for this answer