Menu Close

Python reversed() function

In this article, we are going to learn all about the Python reversed() function. The reversed function is a built-in function python that returns reversed iterator object.

Python reversed() function

Python reversed function is a Python built-in function that is used to returns reversed iterator object.

Syntax

The syntax of reversed function in Python is:-

reversed(sequence)

Parameter

reversed function in Python accepts one parameter sequence.

  • sequence:- sequence can be iterable.

Return Value.

The return value of reversed function in Python is reversed iterator object.

Python reversed function example

Here we will understand Python reversed() function along with example.

Example

my_list = ['Python', 'Java', 'C++', 'C', 'Ruby']
my_tuple = (1, 2, 3, 4, 5, 6, 7)
print(list(reversed(my_list)))
print(list(reversed(my_tuple)))

Output

['Ruby', 'C', 'C++', 'Java', 'Python']
[7, 6, 5, 4, 3, 2, 1]

reversed() function with for loop

You can use python reversed function with python for loop to iterate.

Example

my_list = ['Python', 'Java', 'C++', 'C', 'Ruby']
for i in reversed(my_list):
	print(i)

Output

Ruby
C
C++
Java
Python

Conclusion

In this tutorial, you have learned all about Python’s reversed function along with examples.
reversed function in Python is the best function to reversed any iterable object easily. If you like this article, please share keep visiting for further python tutorials.

Python built-in functions

For more information:- Click Here

Happy Coding
~Vishvajit Rao

Python print() Function
Python classmethod() function

Was this post helpful?

Related Posts

Leave a Reply