In this lesson, you’ll get an overview of what you’ll learn in this course. A list is a collection of arbitrary objects, much like an array in other programming languages. Lists are defined by enclosing a comma-separated sequence of objects in square brackets:
a = ['spam', 'egg', 'bacon', 'tomato']
Here are the important characteristics of Python lists:
- Lists are ordered.
- Lists can contain any arbitrary objects.
- List elements can be accessed by index.
- Lists can be nested to arbitrary depth.
- Lists are mutable.
- Lists are dynamic.
Tuples are identical to lists in all respects, except:
- Tuples are defined by enclosing the elements in parentheses (
()
) instead of square brackets ([]
). - Tuples are immutable.
- Tuples can be packed and unpacked.