Reverse a List using One Line Python Code

In this tutorial, we are going to show How to reverse a list using one line python code. We have added the video tutorial and the source code of the program.

Video Tutorial: Reverse a List using One Line Python Code

What is a List?

A list is an ordered sequence of values. It is a data structure that allows you to store multiple values in a single variable.

Source Code

#Reverse a list using One Line Python Code

myList = [1,2,3,4,5,6]

reversedList = myList[::-1]

print('Reversed List : ',reversedList)

Also Read: Python program to create BMI calculator


Python provides a number of ways to reverse a list. One way is to use the slice operator. The slice operator allows you to extract a range of elements from a list. In order to reverse a list, you can use the slice operator to extract the last elements of the list.

The above example demonstrates how to reverse a list using the slice operator.


Also Read: How to run python in visual studio code

Join Now: Learn Python Programming Masterclass

Leave a Reply

Your email address will not be published. Required fields are marked *