Reversing a list with slicing

suggest change
a = [1, 2, 3, 4, 5]

# steps through the list backwards (step=-1)
b = a[::-1]

# built-in list method to reverse 'a'
a.reverse()

if a == b:
    print(True)

print(b)

# Output: 
# True
# [5, 4, 3, 2, 1]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents