Building Lists With Python's .append() (Summary)
Python provides a method called .append()
that you can use to add items to the end of a given list. This method is widely used either to add a single item to the end of a list or to populate a list using a for
loop. Learning how to use .append()
will help you process lists in your programs.
In this course, you learned:
- How
.append()
works - How to populate lists using
.append()
along with afor
loop - When to replace
.append()
with a list comprehension - How
.append()
works inarray.array()
andcollections.deque()
In addition, you explored some examples of how to use .append()
to create data structures, such as stacks and queues. This knowledge will allow you to use .append()
to grow your lists efficiently and effectively.
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
Great work! Let’s look at everything you’ve done. First and most importantly, you learned how to use the .append()
method. You saw how it’s used to populate lists inside a for
loop, and you saw a different way to populate lists using a list comprehension.
00:19
Remember, a list comprehension is great, but if you need to do additional processing while building the list, you need to go back to the for
loop and using .append()
.
00:28
You learned how to use .append()
in other data structures like arrays and deques.
00:33
Speaking of data structures, you also learned how to implement two very common data structures, stacks and queues, and saw how the .append()
method is used in those implementations. Links to the code files and other useful information at Real Python are provided below.
00:51 I hope you enjoyed this course, and I look forward to seeing you again in another Real Python course.
Become a Member to join the conversation.