5.2 LISTS
A list i a collection of values or an ordered sequence of values/items. The items in alist . be
ofany ype sch string integers, oat, bjt, or even alist Blemets Of ist are ence
in square brackets [separated by commas. Lists are mutable, values in the list can be
modified, which means that Python will not create a new list when you make changes toa
element ofa list. The values that make up alist are called its elements, Elements in alist need
not be of the same type, In other words, we say that lists are heterogeneous (of multiple types
in nature.
Like a string (sequence of characters), list also is a sequenced data type,| For example,
Fruits = ['Mango', "apple! y vgrapes']
Learning |
list of fruits having three
d by comma and
les of lists
In the above example, we have a
items—Mango, Apple and Grapes, separate
enclosed inside square [ | brackets. Other examp
are:
List Types and Examples:
Lists in Python can be broadly classified into three types:
1, Empty Lists
2. Long Lists
) ° Nested Listsjder another list with elements, ‘C//0;‘m’/p/‘u/‘t,‘e,r’ stored
7 ———— Index value
a> ist
22> list = [1c
>>> list(3)
EF
> An IndexError appears if you try and access element that does not
display the error message as: IndexError: list index out of range
‘Type “copyright for more
xination.
>>> list = ['c
S35 liste)
Traceback (mos
File ":
we are having a total of 8 elements for which
ccess the element at index 8, Python will gi