Add Items to List in Python | LiveCodeProgramming
Python Installation First Python Program
Python Basics
Variables Data Types Typecasting Input / Output Operators
Python Simple Programs
Add Two Numbers Simple Interest Area of Circle Students marks Percentage Temperature Conversion Swap Variables Reverse a Number
Python Lists
Python - Lists Python Lists Methods Access List Items Change List Items Add List Items Remove List Items List Items Access by loop List Comprehension Sort Lists Copy Lists Join Lists
Python Tuples
Python - Tuples Access Tuple Items Update Tuples Unpack Tuples Loop Through Tuples Join Tuples Tuple Methods Tuple Delete Tuple Exercises
Python Sets
Python - Sets Access Set Items Add Set Items Remove Set Items Loop Through Sets Update Sets Join Sets Copy Sets Sets intersection Set Operators Set Methods Set Exercises
Python Dictionaries
Python - Dictionaries Access Dictionary Items Change Dictionary Items Add Dictionary Items Remove Dictionary Items Loop Through Dictionary Dictionary Methods
Python Functions
Functions Basics Function Arguments Return Statement Recursion
Conditionals & Loops
If...Else Statements Nested if Else For Loop While Loop Break & Continue
File Handling
Open File Read File Append File Write File File pointer Close File
Error Handling
Try Except Finally Block Raise Exception
Object-Oriented Programming
Classes & Objects Attributes Methods Inheritance Polymorphism
Modules & Packages
Modules Import Statement Packages
Advanced Topics
Lambda Functions Decorators Generators
Python MySQL
MySQL Get Started Create Database Create Table Insert Data Update Data Delete Data Select Data Fetch Data

Adding Items to a List in Python

Python provides several ways to add items to a list. Let's explore append(), insert(), extend(), and dynamic input methods.

Python में list में item जोड़ने के कई तरीके हैं। आइए append(), insert(), extend() और dynamic input method को देखें।

1. Using append()
students = ["Raj", "Simran"]
students.append("Aman")
print(students)
Output:
["Raj", "Simran", "Aman"]
2. Using insert()
students = ["Raj", "Simran"]
students.insert(1, "Aman")
print(students)
Output:
["Raj", "Aman", "Simran"]
3. Using extend()
students = ["Raj", "Simran"]
students.extend(["Aman", "Pooja"])
print(students)
Output:
["Raj", "Simran", "Aman", "Pooja"]
4. Adding Items Dynamically (user input)
students = []
for i in range(3):
    name = input("Enter student name: ")
    students.append(name)
print(students)
Output:
Enter student name: Ravi
Enter student name: Priya
Enter student name: Aman
['Ravi', 'Priya', 'Aman']
5. Using + operator
students = ["Raj", "Simran"]
students = students + ["Aman"]
print(students)
Output:
["Raj", "Simran", "Aman"]