Reverse a list in python without reverse function
Answers
Answered by
9
l = eval(input("Enter a list: "))
print()
print("The list before reversing: ", l)
print()
print("The list after reversing: ", l[::-1])
The above program can be done using string slicing operations.
The act of obtaining a substring from a given string is known as string slicing.
It follows a similar syntax:
- string_name[start:stop:step]
When a negative value is given as the step value, the list will be displayed in reverse order.
Attachments:
Similar questions