Page 288 - Computer Science Class 11 Without Functions
P. 288
12 LISTS AND TUPLES
Chapter Outline
12.1 Lists 12.2 List Assignment
12.3 Traversing a List 12.4 Nested Lists
12.5 Heterogeneous List 12.6 More Operations on Lists
12.7 Using Python's Built-in Functions with List 12. 8 List Methods
12.9 Linear Search 12.10 Tuples
12.11 Tuple Operations 12.12 Tuple Methods
Introduction
In the last chapter, we learnt about strings and their several applications. However, a string is an immutable object,
and we cannot modify the elements of a string. Also, the elements of a string are constrained to be characters. These
restrictions are too harsh to develop practical applications. For example, while dealing with the students' data, we may
like to store their roll numbers, names, addresses, academic records, etc. Also, the data relating to a student, such as
his/her address and academic record, may change over a period of time. To deal with such situations, in this chapter
we will discuss two types of objects, namely, lists and tuples. Elements of a list or tuple may be of arbitrary types.
Whereas lists are mutable, tuples are immutable. Like strings, objects in a list appear in sequence and can be accessed
using indexes.
12.1 Lists
A list comprises a comma-separated sequence of objects enclosed in square brackets []. Like strings, elements of a list
may be accessed using indexing. Let us begin by creating a list of colours.
>>> colors = ['red', 'green', 'blue', 'pink', 'orange', 'white', 'black']
>>> colors
['red', 'green', 'blue', 'pink', 'orange', 'white', 'black']
Non-negative 0 1 2 3 4 5 6
indices
'red' 'green' 'blue' 'pink' 'orange' 'white' 'black'
Negative -7 -6 -5 -4 -3 -2 -1
indices
286 Touchpad Computer Science-XI

