Instagram
youtube
Facebook
Twitter

Python Program to Print List in Reverse Order

A Python Program to Print List in Reverse Order

Code Explanation:

Function Definition:
reverse_list(lst) is defined to reverse the order of elements in the list.

List Slicing:
lst[::-1] is used to reverse the list using Python’s slicing technique.

Return Result:
The reversed list is returned from the function.

Input List:
A sample list [1, 2, 3, 4, 5] is provided.

Function Call & Output:
The function is called with the list and the reversed list is printed.

 

Program:

def reverse_list(lst):

    return lst[::-1]

my_list = [1, 2, 3, 4, 5]

reversed_list = reverse_list(my_list)

print("Reversed list:", reversed_list)