Python .reverse()
Anonymous contributor
Published Oct 29, 2025
Contribute to Docs
The .reverse() method of a Python collections.deque reverses the order of elements in the deque in-place.
Syntax
deque.reverse()
Parameters:
The .reverse() method doesn’t take any parameters.
Return value:
The deque is modified in-place.
Example
In this example, the elements of a deque are reversed in-place, changing the order of items:
from collections import deque# Create a dequed = deque([1, 2, 3, 4])# Reverse the order of deque's elementsd.reverse()print(d)
The output of this code is:
deque([4, 3, 2, 1])
Codebyte Example
The following example reverses the deque in-place to flip the order of words in a sentence:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours