Home » Programming » Python » Python Append List

Appending Items to a List in Python with append() [Examples]

This article will show you how to add items to a list in Python using the append() method.

Lists are a type of Python variable that can hold any number of member elements. They’re analogous to arrays in other programming languages.

Lists can be defined and altered in several ways:

But what if you want to add an item to the end of the list? That’s what the append() list method is for.

append() List Method Syntax

This is a simple method with a simple purpose – and it has simple syntax:

list.append(element)

Note that:

  • list should be a list variable
  • element should be the value or variable you wish to add to the end of the list
    • The value will always be added to the end of the list, becoming the last value in the list but not replacing any existing values.

List append() method Example

Again, not a lot to be said for this one! Here’s the append() method in action:

cars = ['ford', 'oldsmobile', 'kia']
fruits.append('volvo')

Above, a cars variable containing a list of cars is defined. The append() method is then called from the list, passing a new value to be added to the end. The string value ‘volvo’ will be added to the end of the list, with the following resulting list:

['ford', 'oldsmobile', 'kia', 'volvo]
SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment