CodeBlessU
learn code with examples

Python Reverse

Use .reverse() method to reverse elements in sequence (List / Array / Tuple / String).

Syntax:
variable.reverse()
Return Value:
no return value.

List Reverse elements

# Example, List Reverse elements
a1 = [10, 20, 30, 40, 50]

a1.reverse()
print(a1) # [50, 40, 30, 20, 10]

Array Reverse elements

# Example, Array Reverse elements
import array
a1 = array.array('l', [10, 20, 30, 40, 50] )

a1.reverse()
print(a1) # array('l', [50, 40, 30, 20, 10])

In this page...

Copyright © All rights reserved.