Page 140 - Code_GPT_Class_8
P. 140
Quick Quiz
1. What is the purpose of slicing a list in Python?
a. To change the elements of a list b. To extract a portion of the list
2. Which of the following is NOT a valid list method in Python?
a. append() b. substract()
3. Which operation allows you to add a new element to the end of a list in Python?
a. insert() b. append()
Recap
A list is a collection of data elements in a specific order.
Traversing means accessing or visiting the elements of a list.
A nested list can be traversed by using the index operator.
Negative indexing starts from the index of -1, which is the last element of the list: the index of -2
refers to the second last element.
Lists are mutable, which means the elements of a list can be changed or new elements can be
added to a list by using an assignment operator (=).
The various built-in list methods are: append ( ), extend( ), insert(x, a), remove( ), index( ), count( ),
pop([i]), copy( ), clear( ), sort( ), reverse( ).
The various built-in list functions are len(list), max (list) and min(list).
Joining, repeating, slicing and comparing lists are some of the several operations that can be
performed on lists.
Assess Yourself
Choose the correct option.
1. Identify the list function used to remove the first element from the list.
a. pop() b. delete()
c. remove() d. clear()
2. Lists in python are created in brackets.
a. { } b. [ ]
c. ( ) d. < >
CodeGPT (Ver. 4.0)-VIII
138

