Page 357 - Computer Science Class 11 With Functions
P. 357
Let's Summarise
Ø A list comprises a sequence of objects enclosed in square brackets [].
Ø A pair of square brackets [] denotes an empty list.
Ø The len() function returns the number of objects in a list.
Ø (+) operator is used to concatenates a pair of list.
Ø (*) operator produces a list, concatenated with itself a specified number of times.
Ø Traversing a list means accessing each element of a list. This can be done by using looping statement, either
for or while.
Ø List Methods: Methods are defined for list objects. These methods are as follows:
append(elem): inserts the object elem, passed as an argument, at the end of the list.
insert(index, elem): inserts the object elem, passed as an argument, at the specified index and
shifts the existing objects to the right.
extend(lst): inserts the elements in the list lst, passed as an argument, at the end of the elements
of the list lst.
index(elem): returns the index of the first occurrence of the element elem in the list.
reverse(): reverses the order of the elements in the list.
sort(): arranges the elements of the list in the ascending order.
remove(element): searches for the first instance of the element in the list lst and removes it.
pop(index): removes the element from the specified index and returns the element removed from
the list.
Ø The operator in checks for the membership of a data object in the list and returns True or False,
depending on whether the specified object is included in the list or not.
Ø The membership operator not in is used to check the membership of an element in a list. It returns True
if the specific element being looked for is not present in the list, otherwise, False.
Ø There are various other methods available like: lem(), mean(), max(), min(), sum().
Ø A tuple is a sequence of elements, separated by commas and usually enclosed between parentheses().
Ø An empty pair of parentheses defines an empty tuple.
Ø A function tuple() is used to convert a sequence of elements to a tuple.
Ø Tuple Methods: Python provides several methods for manipulating the tuples.
count(element): returns the number of times the given element appears in a tuple.
index(element): returns the index of the first occurrence of an element in a tuple.
sorted(t): sorts the tuple elements in ascending order by default.
Lists and Tuples 355

