GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Deque in Python - GeeksforGeeks Deque in PythonLast Updated : 29 May, 2026 A deque stands for Double-Ended Queue. It is a type of data structure that allows to add and remove elements from both ends efficiently.
![]()
Output deque(['name', 'age', 'DOB']) Accessing Items in dequeA deque also supports indexing, which means elements can be accessed using their position just like lists. Positive indexing starts from the left and negative indexing starts from the right.
Output 1 4 Explanation:
Operations on deque1. append(): adds an element to the right end of the deque.
Output deque([10, 20, 30, 40]) 2. appendleft(): adds an element to the left end of the deque.
Output deque([5, 10, 20, 30]) 3. extend(): adds multiple elements to the right end of the deque.
Output deque([10, 20, 30, 40, 50, 60]) 4. extendleft(): adds multiple elements to the left end of the deque.
Output deque([2, 1, 10, 20, 30]) 5. remove(): removes the first occurrence of a specified value.
Output deque([10, 30, 20]) 6. pop(): removes and returns the element from the right end.
Output deque([10, 20]) 7. popleft(): removes and returns the element from the left end.
Output deque([20, 30]) 8. clear(): removes all elements from the deque.
Output deque([]) 9. len(): returns the total number of elements in the deque.
Output 5 10. count(): returns how many times a specific element appears in the deque.
Output 3 11. rotate(): rotates the elements of the deque.
Output deque([40, 10, 20, 30]) 12. reverse(): reverses the order of elements in the deque.
Output deque([40, 30, 20, 10]) Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |