Page 82 - tp_Modula_v2.0
P. 82
On running the above program, you will get the following output:
Output
13
63
82
Clickipedia
If a user tries to access a list element by using floating-point indexing, it will result in
IndexError.
Traversing Nested Lists
Nested list can be traversed by using the index operator.
Program 3: To create two nested lists.
Program3.py
File Edit Format Run Options Window Help
list=[2, [2002, "Orange", 65.5], [4002, "Orange Education", 46.5]]
print(list[2] [1])
print(list[1] [2])
On running the above program, you will get the following output:
Output
Orange Education
65.5
Negative Indexing
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.
Program 4: Traversing a list by using negative indexing.
Program4.py
File Edit Format Run Options Window Help
list=[13, 25, 41, 63, 82]
print(list[-2])
print(list[-1])
print(list[-4])
On running the above program, you will get the following output:
Output
63
82
25
80 Touchpad MODULAR (Version 2.0)

