Python - Append at Front and Remove from Rear Last Updated : 11 Jul, 2025 Suggest changes Share Like Article Like Report We are given a list we need to append element in front and remove from rear. For example, a = [10, 20, 30] we need to add 5 in front and remove from rear so that resultant output should be [5, 10, 20].Using insertUsing insert in Python allows us to add an element at the front of a list by specifying index 0. To remove from the rear we use pop method without arguments which removes and returns last element of list. Python a = [10, 20, 30] # Append 5 at the front a.insert(0, 5) # Remove the last element a.pop() print(a) Output[5, 10, 20] Explanation:a.insert(0, 5) inserts the element 5 at the front of the list.a.pop() removes the last element (30), resulting in the modified list [5, 10, 20].Using list slicingList slicing enables appending at the front by combining [element] + list. Removing from rear can be done using list[:-1] to exclude the last element.. Python a = [10, 20, 30] # Append 5 at the front using slicing a = [5] + a # Remove the last element using slicing a = a[:-1] print(a) Output[5, 10, 20] Explanation:Element 5 is appended to the front by creating a new list [5] and concatenating it with the original list a.Last element is removed using slicing (a[:-1]), which creates a new list excluding the last element of a.Using collections.dequecollections.deque is a double-ended queue that allows fast appending and popping from both ends. It provides appendleft() to add an element at front and pop() to remove an element from the rear efficiently. Python from collections import deque a = deque([10, 20, 30]) # Append 5 at the front using `appendleft` a.appendleft(5) # Remove the last element using `pop` a.pop() print(list(a)) Output[5, 10, 20] Explanation:a.appendleft(5) adds element 5 to the front of the deque.a.pop() removes last element from the deque, resulting in the modified list [5, 10, 20]. M manjeet_04 Follow 0 Article Tags : Python Python Programs Python list-programs Python DSA-exercises Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like