6. Collections#
This chapter presents Python collections for storing multiple values: lists, tuples, and sets. You will compare ordered, mutable, immutable, and unique-value containers so you can choose the right structure for a task.
Creating and using lists, tuples, and sets
Accessing ordered collections with indexes and slices
Adding, removing, and transforming mutable collections
Comparing mutability, aliasing, copying, and uniqueness
Applying common collection idioms used in everyday Python
Video
This overview introduces Python sequence containers, including lists and tuples, and contrasts them with sets.
Python Tutorial for Beginners 4: Lists, Tuples, and Sets by Corey Schafer
Learning Goals
By the end of this chapter, you will be able to:
Construct and manipulate Python lists using indexing, slicing, and core list methods
Explain object identity, aliasing, shallow copies, and deep copies
Predict how lists behave when passed to functions
Use list comprehensions, unpacking,
enumerate(),zip(), and sorting patterns