×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python - Add List Items

Last Updated : May 01, 2025

You can add items to a Python list using various methods like append() or insert(). The append() method adds an item to the end of the list, while insert() allows you to add an item at a specific index. In this chapter, we will learn different approaches with the help of examples to add list items.

Adding an Item Using append()

The append() method adds a single item to the end of the list. This is a straightforward way to increase the size of your list by adding one element at a time.

Example

In this example, we are adding a new city to the end of the list using the append() method.

# Creating a list of cities
cities = ["New York", "London", "Paris", "Berlin"]

# Adding a city to the end of the list
cities.append("Tokyo")

# Displaying the updated list
print(cities)

The output of the above code would be:

['New York', 'London', 'Paris', 'Berlin', 'Tokyo']

Adding an Item at a Specific Position Using insert()

The insert() method allows you to insert an item at a specific position in the list. The syntax is list.insert(index, item), where index is the position you want to insert the item at, and item is the value you want to add.

Example

In this example, we are adding a city at index 2 in the list of cities using the insert() method.

# Creating a list of cities
cities = ["New York", "London", "Paris", "Berlin"]

# Adding a city at index 2
cities.insert(2, "Sydney")

# Displaying the updated list
print(cities)

The output of the above code would be:

['New York', 'London', 'Sydney', 'Paris', 'Berlin']

Adding Multiple Items Using extend()

The extend() method is used to add multiple items (from another list or any iterable) to the end of the current list. This allows you to append multiple elements in one operation.

Example

In this example, we are adding multiple cities to the list using the extend() method.

# Creating a list of cities
cities = ["New York", "London", "Paris"]

# List of new cities to add
new_cities = ["Tokyo", "Sydney", "Toronto"]

# Adding multiple cities using extend
cities.extend(new_cities)

# Displaying the updated list
print(cities)

The output of the above code would be:

['New York', 'London', 'Paris', 'Tokyo', 'Sydney', 'Toronto']

Adding Multiple Items Using + Operator

You can also use the + operator to concatenate two lists. This creates a new list that combines the items from both lists.

Example

In this example, we are adding multiple cities to the list using the + operator.

# Creating a list of cities
cities = ["New York", "London", "Paris"]

# List of new cities to add
new_cities = ["Tokyo", "Sydney", "Toronto"]

# Adding multiple cities using the + operator
cities = cities + new_cities

# Displaying the updated list
print(cities)

The output of the above code would be:

['New York', 'London', 'Paris', 'Tokyo', 'Sydney', 'Toronto']

Exercise

Select the correct option to complete each statement about adding items to a Python list.

  1. Which method is used to add an item to the end of a list?
  2. How would you add the item 50 at the second position in the list my_list = [10, 20, 30]?
  3. What does my_list = [1, 2] + [3, 4] return?

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.