In Python, you can use the list.append method to add items to the end of a list. If you want to specify where an item should appear in the list, you'll want to use the list.insert method instead. This wikiHow article will show you two different ways to add items to lists in Python loops.

Method 1
Method 1 of 2:
Appending to the End of a List

  1. 1
    Use list.append(item) to add items to the end of a list. You'll also use list.append when you want to populate an empty list with specific items. Replace list with the name of your list, and item with the item you want to add.[1] In this example, we want to add the numbers 0 through 9 to an empty list. We'll use a for loop to do so:
    numberList = []
    for i in range(10):
         numberList.append(i)
    print('List of all numbers:', numberList)
    
    • The output would be List of all numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    • Because we defined i as range(10), using numberList.append(i) added the numbers 0 through 9 to our list.

Method 2
Method 2 of 2:
Adding to Specific Position in a List

  1. 1
    Use list.insert(position, item) to insert an item at a specific location. You'll replace list with the name of your list, position with the position in the list into which you want to insert the new item, and item with the item you're adding.[2] In this example, we'll use a for loop to insert the word orange into our list of colors. We want our list to be in alphabetical order, so we'll place orange at position 3 (between green and pink):
    colorList = ['blue', 'green', 'pink', 'purple', 'red', 'yellow']
    for i in colorList: 
         print(i)
         colorList.insert(3, orange) 
    print('All colors:')
    for l in colorList: 
         print(l)
    
    • We'd see two things in the output: the first would be a list of the colors in the list (without orange added), and the second would be a list of all colors including orange at the position we specified.

About This Article

Nicole Levine, MFA
Written by:
Tech Specialist
This article was written by Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.
How helpful is this?
Co-authors: 3
Updated: November 26, 2021
Views: 324