Page 88 - tp_Modula_v2.0
P. 88
On running the above program, you will get the following output:
Output
Traceback (most recent call last):
File "C:/Users/admin/Desktop/Python code/program 7.11.py", line 2, in
<module>
print(list[5])
IndexError: list index out of range
Recap
List is a homogeneous or heterogenous collection of data elements.
Traversing means accessing or visiting the elements of a list.
Nested list can be traversed by using the index operator.
Negative indexing means the index of -1 refers to the last elements of the list, the index of -2
refers to the second last element.
Lists is mutable which means the elements of a list can be changed or new elements can be
added into a list by using an assignment operator (=).
Joining, repeating, slicing and comparing list are the several operations which can be performed
on lists.
append( ), extend( ), insert(x, a), remove( ), index( ), count( ), pop([i]), copy( ), clear( ), sort( ),
reverse( ) are the various built-in list methods.
len(list), max(list), min(list) are the various built-in functions.
Exercise
A. Tick ( ) the correct option.
1. Which of the following indicates an empty list?
a. { } b. [ ]
c. ( ) d. <>
2. Which of the following list contains another list?
a. Nested list b. Empty list
c. Joint list d. None of these
3. Which of the following does negative indexing means?
a. index of -0 refers to the last elements of the list
b. index of -1 refers to the last elements of the list
c. index of -2 refers to the last elements of the list
d. index of -3 refers to the last elements of the list
86 Touchpad MODULAR (Version 2.0)

