Write a Python program to reverse a given list.
n=[1,2,35,4]
print(n[::-1])
Output :
[4, 35, 2, 1]
The expression n[::-1]
is used to create a new list that contains the elements of n
in reverse order. The [::-1]
part is called slicing with a step value of -1, which means it starts from the last element and goes backward, including all elements.
If you are a beginner and want to know more about Python programming, you can read my Basics of Python blogs (From part 1 to part 15).
HAPPY LEARNING !!!