You can do it in 2 ways:
- Using user-defined-functions
- Using [::-1] operator
Using user-defined-functions:
EXAMPLE:
def myfunc(a):
rev_str = []
for x in a:
rev_str.insert(0, x)
return rev_str
print(myfunc([1,2,3,4,5]))
OUTPUT:
[5, 4, 3, 2, 1]
Using [::-1]:
EXAMPLE:
y=[1,2,3,4,5]
z=y[::-1]
print(z)
OUTPUT:
[5, 4, 3, 2, 1]