How do I reverse an array in Python?
Reverse an array in python
Reverse an array in Python is simple. In python there is various method to reverse an array that is slicing method, using the reverse method, using the reversed method, etc.
1. Using Slicing method in python 3 :
arr = [1,2,3,4,5,6,7,8,9,0]
print(“the original array is :” , arr);
rev = arr[::-1]
print(“the reverse an array is :”rev);
2. Using Reverse method:
arr = [1,2,3,4,5,6,7,8,9]
arr.reverse()
print(“the reverse an array is :”,arr);
3. Using Reversed method:
arr = [1,2,3,4,5,6]
res = list(reversed(arr))
print(“the reverse an array is :”,res);
Note: indentation is more important in python without indentation it will give you an error that is indentation array.
Comments
Post a Comment