NEW
Font size
WorksheetsSequences-2
Total questions: 10
Worksheet time: 10mins
Suppose list1 is [1, 5, 9], what is sum(list1)?
1
9
15
Error
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
[2, 33, 222, 14]
Error
25
[25, 14, 222, 33, 2]
If a=(1,2,3,4), a[1:-1] is _________
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
What will be the output of the following Python code?
>>> a=(1,2,(4,5))
>>> b=(1,2,(3,4))
>>> a<b
False
True
Error, < operator is not valid for tuples
Error, < operator is valid for tuples but not if there are sub-tuples
What will be the output of the following Python code?
>>>example = "snow world"
>>>print("%s" % example[4:7])
wo
world
sn
rl
What will be the output of the following Python code snippet?
>>> print([i+j for i in "abc" for j in "def"])
[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]
[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]
If a={5,6,7,8}, which of the following statements is false?
print(len(a))
print(min(a))
a.remove(5)
a[2]=45
If a={5,6,7}, what happens when a.add(5) is executed?
a={5,5,6,7}
a={5,6,7}
Error as there is no add function for set data type
Error as 5 already exists in the set
What will be the output of the following Python code snippet?
>>>d = {"john":40, "peter":45}
>>>print(list(d.keys()))
[“john”, “peter”]
[“john”:40, “peter”:45]
(“john”, “peter”)
(“john”:40, “peter”:45)
Which of the following is not a declaration of the dictionary?
{1: ‘A’, 2: ‘B’}
dict([[1,”A”],[2,”B”]])
{1,”A”,2”B”}
{ }
