how to use reverse in python code example

Example 1: reverse list python

>>> the_list = [1,2,3]
>>> reversed_list = the_list.reverse()
>>> list(reversed_list)
[3,2,1]

OR

>>> the_list = [1,2,3]
>>> the_list[::-1]
[3,2,1]

Example 2: reverse in python 3

# create list of integers or strings 
number = [1,2,3,4,5]
# pass the values using the reverse method.
number.reverse()
# Then print the variable as such:
print(number)

Example 3: reverse list python

list=[1,2,3]
list[::-1]

Example 4: reverse function python

# The Reverse operation - Python 3:
Some_List = [1, 2, 3, 4, 1, 2, 6]  
Some_List.reverse()  
print(Some_List)
# Result: [6, 2, 1, 4, 3, 2, 1]

Example 5: python reverse

my_list = [1, 2, 3]
my_list.reverse()           # my_list is modified
print(my_list)              # '[3, 2, 1]'
my_revert = my_list[::-1]   # my_list stays [3, 2, 1]
print(my_revert)            # '[1, 2, 3]'
# Item by item reverse with range(<start>, <end>, <step>)
for i in range(len(my_list), 0, -1):		# my_list is [3, 2, 1]
    print(my_list[i-1])		# '1' '2' '3'
for i in reversed(range(len(my_list))):
    print(my_list[i])       # '1' '2' '3'