Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
round() function in Python
Next article icon

Python reversed() Method

Last Updated : 08 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

reversed() function in Python lets us go through a sequence like a list, tuple or string in reverse order without making a new copy. Instead of storing the reversed sequence, it gives us an iterator that yields elements one by one, saving memory. Example:

Python
a = ["nano", "swift", "bolero", "BMW"] print(list(reversed(a))) 

Output
['BMW', 'bolero', 'swift', 'nano'] 

Explanation: The list a is passed to reversed(), which returns an iterator. The list() convert the iterator into a list and display the reversed order.

Syntax of reversed()

reversed(sequence) 

Parameter: input sequence that needs to be reversed. It must be an iterable such as a list, tuple, string or range.

Returns: an iterator that produces the elements of the sequence in reverse order.

Note: reversed() function does not work with sets because they are unordered collections.

Examples of reversed()

Example 1: Using reversed() with tuples and ranges

Python
# For tuple tup = ('g', 'e', 'e', 'k', 's') print(list(reversed(tup)))  # For range r = range(1, 5) print(list(reversed(r))) 

Output
['s', 'k', 'e', 'e', 'g'] [4, 3, 2, 1] 

Explanation: The tuple tup and range r are passed to reversed(), which returns an iterator. The list() converts it into a list, displaying the reversed sequence. The tuple’s characters appear in reverse and range(1,5) producing [1, 2, 3, 4] results in [4, 3, 2, 1].

Example 2: Using reversed() in a for loop

Python
s = "Python is great"  # reverse the string for char in reversed(s):     print(char, end="") 

Output
taerg si nohtyP

Explanation: The for loop iterates over the reversed string, printing characters in reverse without a newline, displaying the string in a single line.

Example 3: Reversing a string as a list

Python
s = "Geeksforgeeks" print(list(reversed(s))) 

Output
['s', 'k', 'e', 'e', 'g', 'r', 'o', 'f', 's', 'k', 'e', 'e', 'G'] 

Explanation: string s is passed to reversed(), which returns an iterator. The list() converts it into a list of characters in reverse order.

Handling Exception in reversed()

If we try to fetch elements from the iterator beyond its range, a StopIteration exception occurs.

Python
a = [1, 2, 3]  # Reverse the list b = reversed(a)  # Print the reversed elements one by one using the `next` function print(next(b))   print(next(b))   print(next(b))    print(next(b))  # Exception 

Output

3
2
1
StopIteration
print(next(my_list_rev)) # Exception
Line 11 in <module> (Solution.py)

Explanation: list a is passed to reversed(), returning an iterator b. The next() function retrieves 3, 2, and 1. Calling next(b) again raises a StopIteration exception as the iterator is exhausted.

    original_tuple = (1, 2, 3, 4, 5)
    reversed_tuple = tuple(reversed(original_tuple))
    print(reversed_tuple) # Output: (5, 4, 3, 2, 1)
    • Tuples: Yes, you can use reversed() with tuples, and it will return an iterator.
    • Sets: No, you cannot use reversed() with sets because sets are unordered collections and do not maintain any specific order.


    Next Article
    round() function in Python
    author
    pawan_asipu
    Improve
    Article Tags :
    • Python
    • python
    • Python-Functions
    Practice Tags :
    • python
    • python
    • python-functions

    Similar Reads

    • Python 3 - input() function
      In Python, we use the input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function converts it into a string. Python input() Function SyntaxSyntax: input(prompt) Parameter: Prompt: (optio
      3 min read
    • Python int() Function
      The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part. Example: In this example, we passed a string as an argument to the int() function and printed it. [GFGTABS] Python age = "21"
      4 min read
    • Python len() Function
      The len() function in Python is used to get the number of items in an object. It is most commonly used with strings, lists, tuples, dictionaries and other iterable or container types. It returns an integer value representing the length or the number of elements. Example: [GFGTABS] Python s = "G
      2 min read
    • Python map() function
      The map() function is used to apply a given function to every item of an iterable, such as a list or tuple, and returns a map object (which is an iterator). Let's start with a simple example of using map() to convert a list of strings into a list of integers. [GFGTABS] Python s = ['1', '
      4 min read
    • Python - max() function
      Python max() function returns the largest item in an iterable or the largest of two or more arguments. It has two forms. max() function with objectsmax() function with iterablePython max() function With ObjectsUnlike the max() function of C/C++, the max() function in Python can take any type of obje
      4 min read
    • memoryview() in Python
      The memoryview() function in Python is used to create a memory view object that allows us to access and manipulate the internal data of an object without copying it. This is particularly useful for handling large datasets efficiently because it avoids the overhead of copying data. A memory view obje
      5 min read
    • Python min() Function
      Python min() function returns the smallest value from a set of values or the smallest item in an iterable passed as its parameter. It's useful when you need to quickly determine the minimum value from a group of numbers or objects. For example: [GFGTABS] Python a = [23,25,65,21,98] print(min(a)) b =
      4 min read
    • Python next() method
      Python's next() function returns the next item of an iterator. Example Let us see a few examples to see how the next() method in Python works. C/C++ Code l_iter = iter(l) print(next(l_iter)) Output1 Note: The .next() method was a method for iterating over a sequence in Python 2. It has been replaced
      4 min read
    • Python oct() Function
      Python oct() function takes an integer and returns the octal representation in a string format. In this article, we will see how we can convert an integer to an octal in Python. Python oct() Function SyntaxSyntax : oct(x) Parameters: x - Must be an integer number and can be in either binary, decimal
      2 min read
    • ord() function in Python
      Python ord() function returns the Unicode code of a given single character. It is a modern encoding standard that aims to represent every character in every language. Unicode includes: ASCII characters (first 128 code points)Emojis, currency symbols, accented characters, etc.For example, unicode of
      2 min read
    geeksforgeeks-footer-logo
    Corporate & Communications Address:
    A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
    Registered Address:
    K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
    GFG App on Play Store GFG App on App Store
    Advertise with us
    • Company
    • About Us
    • Legal
    • Privacy Policy
    • In Media
    • Contact Us
    • Advertise with us
    • GFG Corporate Solution
    • Placement Training Program
    • Languages
    • Python
    • Java
    • C++
    • PHP
    • GoLang
    • SQL
    • R Language
    • Android Tutorial
    • Tutorials Archive
    • DSA
    • Data Structures
    • Algorithms
    • DSA for Beginners
    • Basic DSA Problems
    • DSA Roadmap
    • Top 100 DSA Interview Problems
    • DSA Roadmap by Sandeep Jain
    • All Cheat Sheets
    • Data Science & ML
    • Data Science With Python
    • Data Science For Beginner
    • Machine Learning
    • ML Maths
    • Data Visualisation
    • Pandas
    • NumPy
    • NLP
    • Deep Learning
    • Web Technologies
    • HTML
    • CSS
    • JavaScript
    • TypeScript
    • ReactJS
    • NextJS
    • Bootstrap
    • Web Design
    • Python Tutorial
    • Python Programming Examples
    • Python Projects
    • Python Tkinter
    • Python Web Scraping
    • OpenCV Tutorial
    • Python Interview Question
    • Django
    • Computer Science
    • Operating Systems
    • Computer Network
    • Database Management System
    • Software Engineering
    • Digital Logic Design
    • Engineering Maths
    • Software Development
    • Software Testing
    • DevOps
    • Git
    • Linux
    • AWS
    • Docker
    • Kubernetes
    • Azure
    • GCP
    • DevOps Roadmap
    • System Design
    • High Level Design
    • Low Level Design
    • UML Diagrams
    • Interview Guide
    • Design Patterns
    • OOAD
    • System Design Bootcamp
    • Interview Questions
    • Inteview Preparation
    • Competitive Programming
    • Top DS or Algo for CP
    • Company-Wise Recruitment Process
    • Company-Wise Preparation
    • Aptitude Preparation
    • Puzzles
    • School Subjects
    • Mathematics
    • Physics
    • Chemistry
    • Biology
    • Social Science
    • English Grammar
    • Commerce
    • World GK
    • GeeksforGeeks Videos
    • DSA
    • Python
    • Java
    • C++
    • Web Development
    • Data Science
    • CS Subjects
    @GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
    We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
    Lightbox
    Improvement
    Suggest Changes
    Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
    geeksforgeeks-suggest-icon
    Create Improvement
    Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
    geeksforgeeks-improvement-icon
    Suggest Changes
    min 4 words, max Words Limit:1000

    Thank You!

    Your suggestions are valuable to us.

    What kind of Experience do you want to share?

    Interview Experiences
    Admission Experiences
    Career Journeys
    Work Experiences
    Campus Experiences
    Competitive Exam Experiences