Reverse List
Reverse a list in-place using slicing.
BeginnerTopic: List Programs
Python Reverse List Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to reverse a list
items = input("Enter list elements separated by space: ").split()
reversed_items = items[::-1]
print("Reversed list:", reversed_items)Output
Enter list elements separated by space: 1 2 3 Reversed list: ['3', '2', '1']
Understanding Reverse List
We use slicing `items[: :-1]` to create a reversed copy of the list.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.