OneBite.Dev - Coding blog in a bite size

reverse arrays items in python

Code snippet on how to reverse arrays items in python

  my_array = [1, 2, 3, 4, 5]
  my_array.reverse() 

This code reverses items in an array, in this case, an array with the integers 1, 2, 3, 4 and 5. It takes the array, named “my_array”, and then applies the “.reverse()” function to it. The “.reverse()” function will reverse the order of the elements in the array and give a result of [5, 4, 3, 2, 1]. This is the reversed version of the array, and the order of the elements in the array have been changed.

python