Reverse List in Python
Reverse a list in-place using slicing.
BeginnerList ProgramsExample 10 of 25
reverse-list.py
1# Program to reverse a list23items = input("Enter list elements separated by space: ").split()45reversed_items = items[::-1]67print("Reversed list:", reversed_items)
Output
Enter list elements separated by space: 1 2 3 Reversed list: ['3', '2', '1']
What's going on
We use slicing items[::-1] to create a reversed copy of the list.
After this program
If the idea is still fuzzy, read Day 5: Lists and List Methods in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 list programs, or see every topic on Python exercises.