Personal Blog
Programming

Python Tips & Tricks

How to reverse an array:

a ="ApplePie"
print("Reverse is", a[::-1])

Output:

Reverse is eiPelppA

How to swap two values:

x, y = 10, 20
print(x, y)
x, y = y, x
print(x, y)

Output:

10 20
20 10

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top