Python extend()
Anonymous contributor
Published Oct 29, 2025
Contribute to Docs
The extend() method adds multiple elements to the right end of a deque from any iterable (like a list, tuple, or another deque). It modifies the deque in place and returns None.
Syntax
deque.extend(iterable)
Parameters:
iterable: A sequence or iterable whose elements will be added to the right end of the deque.
Return value:
This method does not return any value. It modifies the deque in-place.
Example
In this example, extend() adds elements from a list and another deque to the right end of a deque:
from collections import deque# Create a dequedq = deque([1, 2, 3])# Extend itdq.extend([4, 5, 6])print("Extending with list: ", dq)#Extend it using another dequedq.extend(deque([7, 8, 9]))print("Extending with another deque: ", dq)
This example results in the following output:
Extending with list: deque([1, 2, 3, 4, 5, 6])Extending with another deque: deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
Codebyte Example: Extending a deque with a list and a tuple
In this example, extend() adds elements from a list and a tuple, demonstrating its ability to handle different iterables:
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