/* ............... START ............... */
// Using a for loop:
def reverse_array(arr):
n = len(arr)
for i in range(n // 2):
arr[i], arr[n - i - 1] = arr[n - i - 1], arr[i]
# Example usage:
my_array = [1, 2, 3, 4, 5]
reverse_array(my_array)
print(my_array) # Output: [5, 4, 3, 2, 1]
// Using list slicing:
def reverse_array(arr):
arr[:] = arr[::-1]
# Example usage:
my_array = [1, 2, 3, 4, 5]
reverse_array(my_array)
print(my_array) # Output: [5, 4, 3, 2, 1]
// Using the reverse() method:
def reverse_array(arr):
arr.reverse()
# Example usage:
my_array = [1, 2, 3, 4, 5]
reverse_array(my_array)
print(my_array) # Output: [5, 4, 3, 2, 1]
/* ............... END ............... */