Code has been added to clipboard!

Using the Python Append Method

Reading time 2 min
Published Feb 10, 2020
Updated Feb 10, 2020

TL;DR – The Python append method allows you to add an extra item at the end of a specified list.

The append function in Python

Lists are among the most commonly used data types in Python. They contain multiple elements: strings, numbers, dictionaries, etc. To add an extra element at the end of the list, we use the Python append function:

Example
xList = ['yellow', 'red', 'blue'];
xList.append('green');

You can even append Python lists with other lists:

Example
xList = ['yellow', 'red', 'blue'];
yList = ['1', '2', '3']
xList.append(yList);
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid certificates of completion
Coursera
Pros
  • Professional service
  • Flexible timetables
  • A variety of features to choose from
Main Features
  • Professional certificates of completion
  • University-level courses
  • Multiple Online degree programs
Datacamp
Pros
  • Great user experience
  • Offers quality content
  • Very transparent with their pricing
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable

The syntax for append in Python

Using the Python append method is simple – all you need to define is the list and the element to add:

Example
list.append(element)

The append function in Python doesn't have a return value: it doesn't create any new, original lists. Instead, it updates a list that already exists, increasing its length by one.

Python append: useful tips

  • To add elements of a list to another list, use the extend method. This way, the length of the list will increase by the number of elements added.
  • To add an element to a specified location and not the end of the list, use the insert method. It takes two arguments: the index of the element it will be inserted after, and the new element to insert.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 30/11/2020
3176 People Used
Only 97 Left
Rating
5.0