Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Building Lists With Python's .append() (Overview)

Adding items to a list is a fairly common task in Python, so the language provides a bunch of methods and operators that can help you out with this operation. One of those methods is .append(). With .append(), you can add items to the end of an existing list object. You can also use .append() in a for loop to populate lists programmatically.

In this course, you’ll learn how to:

  • Work with .append()
  • Populate lists using .append() and a for loop
  • Replace .append() with list comprehensions
  • Work with .append() in array.array() and collections.deque()

Download

Sample Code (.zip)

4.9 KB

Download

Course Slides (.pdf)

1.8 MB

00:00 Hello, and welcome to this course on using Python’s .append() method. Lists are frequently used in Python programs that work with collections of data, and .append() is one of the most commonly used methods to work with lists.

00:14 In this fairly short course, you’ll learn some of the best ways to use .append().

00:20 To see why this is useful, let’s start by looking at the Python list. As I mentioned, it’s common for a program to work on collections of data. The list is one of the most common data structures used to store and access those collections in Python programs, and the .append() method is the primary way data elements are added to a list.

00:43 So if you’re wanting to learn how to properly and effectively use the .append() method, then this is the course for you.

00:51 Once you’ve completed this course, you should be able to write Pythonic code using the .append() method, use the .append() method to populate lists in a for loop, learn a popular, alternate way to populate a list called a list comprehension, and learn how .append() can be used in other types of data structures such as arrays and double-ended queues, also known as deques.

01:17 This course is related to a tutorial by Leodanis Ramos called Python’s .append(): Add Items to Your Lists in Place. I do follow it pretty closely, so feel free to follow along with that tutorial as you go through this course.

01:32 These are the software tools I use in this course. If you use other programs, then things will look a little bit different than what you’re familiar with.

01:40 For my program files, I use Visual Studio Code. I do have all of the code examples in the slides, but I’ll probably describe the examples in VS Code. All of my code files are available by a link in this course, so you’ll have both the slides and the actual files to refer to when wanting to look back at the examples.

02:00 I’m working on a Mac and I use iTerm for my terminal shell. For other systems, you might be looking to use another terminal or maybe something called a command shell or PowerShell. For interactive Python, I use a REPL called ptpython.

02:15 I like the way its syntax coloring looks in these lessons.

02:21 So, let’s get started by looking at the basics of the .append() method.

Become a Member to join the conversation.