Friday 4 December 2015

Python: list: Reverse elements of list

List provides reverse method to reverse elements of list.

test.py

list=[12, 5, 32, 43, 21, 356, 5, 21]
print(list)

list.reverse()
print(list)

$ python3 test.py
[12, 5, 32, 43, 21, 356, 5, 21]
[21, 5, 356, 21, 43, 32, 5, 12]




Previous                                                 Next                                                 Home

No comments:

Post a Comment