Contents

To shuffle the list(say list1) what function do we use?
a) list1.shuffle()
b) shuffle(list1)
c) random.shuffle(list1)
d) random.shuffleList(list1)

c

Explanation: Execute in the shell to verify.


Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
a) print(list1[2:])  
b) print(list1[:2])
c) print(list1[:-2]) 
d) all of these

d

Explanation: Slicing is allowed in lists just as in the case of strings.


Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
a) Error                                 
b) None
c) 25                                      
d) 2

c

Explanation: -1 corresponds to the last index in the list.


Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
a) [2, 33, 222, 14]               
b) Error
c) 25
d) [25, 14, 222, 33, 2]

a

Explanation: Execute in the shell to verify.


Suppose list1 is [1, 3, 2], What is list1 * 2?
a) [2, 6, 4]                             
b) [1, 3, 2, 1, 3]
c) [1, 3, 2, 1, 3, 2]
d) [1, 3, 2, 3, 2, 1]

c

Explanation: Execute in the shell and verify.


Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
a) [0, 1, 2, 3]                        
b) [0, 1, 2, 3, 4]
c) [0.0, 0.5, 1.0, 1.5]
d) [0.0, 0.5, 1.0, 1.5, 2.0]

c

Explanation: Execute in the shell to verify.