Introduction to Lists
Learn about the usage of lists in Python.
We'll cover the following
A container is an entity that contains multiple data items. It is also known as a collection or a compound data type.
Python has the following container data types:
- Lists
- Tuples
- Sets
- Dictionaries
What are lists?
A list can grow or shrink during the execution of the program. Therefore, it is also known as a dynamic array. For this reason, they are commonly used for handling variable-length data.
A list is defined by writing comma-separated elements within []
.
num = [10, 25, 30, 40, 100]
names = ['Noah', 'Emma', 'Amelia', 'Oliver']
A list can contain dissimilar types, though usually, they are a collection of similar types, for example:
animal = ['Zebra', 155.55, 110]
Items in a list can be repeated, i.e., a list may contain duplicate items. Like printing, *
can be used to repeat an element multiple times. An empty list is also feasible.
Get hands-on with 1200+ tech skills courses.