Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
How to Append Elements to a List in Python - How to Append Elements to a List in Python

How to Append Elements to a List in Python

Posted on January 5, 2025January 8, 2025 By Rishabh saini No Comments on How to Append Elements to a List in Python

How to Append Elements to a List in Python

In Python, lists are dynamic data structures that allow us to add elements in various ways. Python comes with a number of built-in techniques for extending or appending lists. These methods not only enable us to add individual elements but also allow for appending multiple elements or even entire iterables to a list.

Complete Python Course with Advance topics:-Click here

How to Append Elements to a List in Python

Here, we will discuss three popular methods for appending elements to a list:

  1. append(elmt): Adds a component to the list’s end.
  2. insert(index, elmt): Inserts an element at a specified index.
  3. extend(iterable): Adds items from an iterable to the list to make it longer.

1. append(elmt)

One element is added at the end of the list using the append() method. This is particularly useful when you want to grow a list incrementally.

Example:

names = ["Joseph", "Peter", "Cook", "Tim"]

print('Current names List is:', names)

new_name = input("Please enter a name:\n")
names.append(new_name)  # Using the append() method

print('Updated names List is:', names)

Output:

Current names List is: ['Joseph', 'Peter', 'Cook', 'Tim']
Please enter a name:
Devansh
Updated names List is: ['Joseph', 'Peter', 'Cook', 'Tim', 'Devansh']

2. insert(index, elmt)

An element can be added at a specified index using the insert() method. This is particularly useful when you need precise control over the position of the new element.

Example:

list1 = [10, 20, 30, 40, 50]

print('Current Numbers List:', list1)

list1.insert(3, 77)  # Inserting 77 at index 3
print("The list after first insertion:", list1)

n = int(input("Enter a number to add to the list:\n"))
index = int(input("Enter the index to add the number:\n"))

list1.insert(index, n)  # Adding user-specified element at the given index
print('Updated Numbers List:', list1)

Output:

Current Numbers List: [10, 20, 30, 40, 50]
The list after first insertion: [10, 20, 30, 77, 40, 50]
Enter a number to add to the list:
45
Enter the index to add the number:
1
Updated Numbers List: [10, 45, 20, 30, 77, 40, 50]

3. extend(iterable)

The extend() method allows you to add elements from an iterable (e.g., another list, tuple, or string) to the end of the list. Unlike append(), which adds the entire iterable as a single element, extend() adds each element of the iterable individually.

Example:

list1 = [10, 20, 30]

list1.extend(["52.10", "43.12"])  # Extending with a list
print("After extending with a list:", list1)

list1.extend((40, 30))  # Extending with a tuple
print("After extending with a tuple:", list1)

list1.extend("Apple")  # Extending with a string
print("After extending with a string:", list1)

Output:

After extending with a list: [10, 20, 30, '52.10', '43.12']
After extending with a tuple: [10, 20, 30, '52.10', '43.12', 40, 30]
After extending with a string: [10, 20, 30, '52.10', '43.12', 40, 30, 'A', 'p', 'p', 'l', 'e']

Key Differences Between Methods

MethodAdds at PositionAdds Multiple ElementsAccepts Iterable
append(elmt)End of the listNoNo
insert(index, elmt)Specified indexNoNo
extend(iterable)End of the listYesYes

Download New Real Time Projects :-Click here
PHP PROJECT:- CLICK HERE


how to append elements to a list in python using for loop
how to append multiple elements to a list in python
how to append multiple lists to a list in python
how to append elements to a list in python
how to append elements to a list in python another list
how to append elements to an empty list in python
how to append an item to a list in python
how to add an element to a list in python
how to add elements to an empty list in python
how to insert an element to a list in python
how to append elements to a list in python example
how to append elements to a list in python w3schools
how to append elements to a list in python using for loop

Post Views: 939
Python Interview Question Tags:how to append a list in python, how to append elements in list in python, how to append to a 2d list in python, how to append to a list in python, list in python, Python, python append, python append list to another list, python append to array, python append to dictionary, python append to file, python append to list, python append to set, python append to string, python append to tuple, python list append, python lists

Post navigation

Previous Post: Order Management System using Django Framework
Next Post: Rename Database in SQL Like a Pro : A Comprehensive Guide

More Related Articles

Convert List to Dictionary in Python How to Convert List to Dictionary in Python Python Interview Question
How to Take Input in Python? - Take Input in Python How to Take Input in Python? Python Interview Question
How to Plot a Graph in Python How to Plot a Graph in Python Python Interview Question

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. How to Install Python on Windows: A Step-by-Step Guide
  2. How to Run Python Program: A Comprehensive Guide for Python Programmers
  3. How to Create a Dictionary in Python
  4. How to Install Matplotlib in Python
  5. How to Create a DataFrame in Python
  6. Insertion Sort in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,612)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,210)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,862)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme