WorksheetsSummary module-2
Total questions: 10
Worksheet time: 5mins
1. Which of the following commands will create a list?
a) list1 = list()
b) list1 = []
c) list1 = list([1, 2, 3])
d) all of the mentioned
What is the output when we execute list(“hello”)?
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
[‘hello’]
[‘llo’]
[‘olleh’]
To shuffle the list(say list1) what function do we use?
list1.shuffle()
shuffle(list1)
random.shuffle(list1)
random.shuffleList(list1)
Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
print(list1[0])
print(list1[:2])
print(list1[:-2])
all of the mentioned
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
[2, 33, 222, 14]
Error
25
[25, 14, 222, 33, 2]
Which of the following statements create a dictionary?
d = {}
d = {“john”:40, “peter”:45}
d = {40:”john”, 45:”peter”}
All of the mentioned
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
"john" in d
True
False
None
Error
Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?
d.delete(“john”:40)
d.delete(“john”)
del d[“john”]
del d(“john”:40)
Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?
Since “susan” is not a value in the set, Python raises a KeyError exception
It is executed fine and no exception is raised, and it returns None
Since “susan” is not a key in the set, Python raises a KeyError exception
Since “susan” is not a key in the set, Python raises a syntax error
What will be the output of the following Python code?
t = (1, 2)
2 * t
(1, 2, 1, 2)
[1, 2, 1, 2]
(1, 1, 2, 2)
[1, 1, 2, 2]
