34: Traverse a List in Reverse Order - 1000+ Python Programming


Question: Write a Python Program to Traverse a List in Reverse Order


Solution 1: using reversed() function

number_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for num in reversed(number_list):
    print(num)
Output:
9
8
7
6
5
4
3
2
1

Solution 2: using slicing

number_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for num in my_list[::-1]:
    print(num)
Python Program - Traverse a List in Reverse Order

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap