NEW
Font size
WorksheetsQUIZ ON STRINGS - TUPLES - SET - DICTIONARY
Total questions: 25
Worksheet time: 13mins
What will be the output of the following Python code?
print("Hello {name1} and {name2}".format(name1='Covalence', name2='Global'))
Hello Covalense and Global
Hello {name1} and {name2}
Error
Covalense and Global
What will be the output of the “hello” +1+2+3?
hello123
hello
hello6
Error
What is “Hello”.replace(“l”, “e”)?
Heeeo
Heelo
Heleo
None
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy'))
2
0
5
Error
What will be the output of the following Python code?
print("abcdef".find("cd"))
True
2
False
Error
What will be the output of the following Python code?
print('xyyzxxyxyy'.lstrip('xyy'))
zxxyxyy
zxxy
z
Error
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
print(t[3])
t[3] = 45
print(max(t))
print(len(t))
What will be the output of the following Python code?
>>>t=(1,2,4,3)
>>>t[1:-1]
(1, 2)
(1, 2, 4)
(2, 4)
(2, 4, 3)
What will be the output of the following Python code?
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
1
2
5
Error
What type of data is: a=[(1,1),(2,4),(3,9)]?
Array of tuples
List of tuples
Tuples of lists
Invalid type
What will be the output of the following Python code?
>>> a=(1,2)
>>> b=(3,4)
>>> c=a+b
>>> print(c)
(4,6)
(1,2,3,4)
Error as tuples are immutable
None
What will be the output of the following Python code?
>>>nums = set([1,1,2,3,3,3,4,4])
>>>print(len(nums))
7
4
8
Error, invalid syntax for formation of set
Which of the following statements is used to create an empty set?
{ }
set()
[ ]
( )
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
What will be the output of the following Python code?
>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b
{4,5}
{6}
Error as unsupported operand type for set data type
Error as the duplicate item 6 is present in both sets
Is the following Python code valid?
>>>a={3,4,{7,5}}
>>>print(a[2][0])
Yes, 7 is printed
Error, elements of a set can’t be printed
Error, subsets aren’t allowed
Yes, {7,5} is printed
What will be the output of the following Python code snippet?
for x in set('pqr'):
print(x*2)
pp
rr
pqr
pqr
ppqqrr
pqrpqr
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}
>>>d["john"]
40
45
“john”
“peter”
What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")
1 A 2 B 3 C
1 2 3
A B C
1:”A” 2:”B” 3:”C”
What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
a.clear()
print(a)
None
{ None:None, None:None, None:None}
{1:None, 2:None, 3:None}
{ }
What will be the output of the following Python code?
a={1:5,2:3,3:4}
a.pop(3)
print(a)
{1: 5}
{1: 5, 2: 3}
Error, syntax error for pop() method
{1: 5, 3: 4}
What will be the output of the following Python code snippet?
>>> a={1:"A",2:"B",3:"C"}
>>> del a
method del doesn’t exist for the dictionary
del deletes the values in the dictionary
del deletes the entire dictionary
del deletes the keys in the dictionary
What will be the output of the following Python code snippet?
test = {1:'A', 2:'B', 3:'C'}
test = {}
print(len(test))
0
3
Error
What will be the output of the following Python code?
>>> a={i: i*i for i in range(6)}
>>> a
Dictionary comprehension doesn’t exist
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}
{0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
