Containers and Python Type Jargon
Learn about different containers used to store data and different terms used for Python types.
We'll cover the following
Container types
Container types typically refer to multiple values stored together. Here are some examples of different basic types:
- A list is an indexed collection of similar/dissimilar entities, e.g.,
[10, 20, 30, 20, 30, 40, 50, 10]
,['She', 'sold', 10, 'shells']
. - A tuple is an immutable collection, e.g.,
('Sanjay', 34, 4500.55)
,('Let Us Python', 350, 195.00)
. - A set is a collection of unique values, e.g.,
{10, 20, 30, 40}
,{'Sanjay', 34, 45000}
. - A dictionary is a collection of key-value pairs, with unique keys enclosed in
' '
, e.g.,{'ME101' : 'Strength of materials', 'EE101' : 'Electronics'}
.
Values in a list and tuple can be accessed using their position in the list or tuple. Values in a set can be accessed using a for
loop (discussed in the next chapters). Values in a dictionary can be accessed using a key. This is shown in the following program:
Get hands-on with 1200+ tech skills courses.