B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Add Items to List in Python | LiveCodeProgramming
Python Installation First Python Program Control Flow if...else nested if else match-case logical-operators for loops while loops break / continue Functions Defining Functions Function Arguments Function return value Lambda Function Recursion Exception Handling Exception Handling Try Except Else and Finally Raise Exception Custom Exceptions File Handling File in python Read File Write File Append File Delete File Exception Handling

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"]