Contents

To add a new element to a list we use which command?
a) list1.add(5)                      
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)

b

Explanation: We use the function append to add an element to the list.


To insert 5 to the third position in list1, we use which command?
a) list1.insert(3, 5)               
b) list1.insert(2, 5)
c) list1.add(3, 5)  
d) list1.append(3, 5)

b

Explanation: Execute in the shell to verify.


To remove string “hello” from list1, we use which command?
a) list1.remove(“hello”)
b) list1.remove(hello)
c) list1.removeAll(“hello”)
d) list1.removeOne(“hello”)

a

Explanation: Execute in the shell to verify


Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
a) 0                                                        
b) 1
c) 4                                                        
d) 2

d

Explanation: Execute help(list.index) to get details.


Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
a) 0                                                        
b) 4
c) 1                                                        
d) 2

d

Explanation: Execute in the shell to verify.


Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?
a) [3, 4, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [25, 20, 5, 5, 4, 3, 3, 1]
d) [3, 1, 25, 5, 20, 5, 4, 3]

d

Explanation: Execute in the shell to verify.