NEW
Font size
WorksheetsPython Programming Quiz
Total questions: 24
Worksheet time: 12mins
Which method is used to remove a key-value pair from a dictionary?
remove()
pop()
discard()
delete()
Which method adds an item to a list at the end?
insert()
append()
add()
push()
What is the output of ' '.join(['a','b','c'])?
'abc'
'a, b, c'
'a+b+c'
'a b c'
What is the output of the following code? t = (1,2,[3,4]) t[2].append(5) print(t)
(1, 2, [3, 4])
(1, [3, 4, 5])
Error
(1, 2, [3, 4, 5])
How do you convert a list to a set?
set(list)
tuple(list)
dict(list)
list(set)
What is the output of the following code? stack = [] stack.append(10) stack.append(20) print(stack.pop())
20
10
[]
None
What will `len({})` return?
None
Error
1
0
Which of the following supports LIFO order?
Stack
Queue
List
Dictionary
What is the output of the following code? d = {'a':1, 'b':2} d['a'] += 1 print(d['a'])
'a'
3
2
1
How do you access the first element in a list `a`?
a[0]
a[-1]
a[1]
a.get(0)
Which method adds an item to a list at the end?
add()
insert()
append()
push()
What is the output of the following code? s = {1,2,3,2,1} s.add(4) print(len(s))
6
5
4
3
Which collection type is unordered and does not allow duplicates?
Set
Tuple
Dictionary
List
Which collection allows key-value mapping?
List
Dictionary
Tuple
Set
What does `list('abc')` return?
['a','b','c']
['abc']
('a','b','c')
{'a','b','c'}
What is the output of the following code? t = (1,2,[3,4]) t[2].append(5) print(t)
(1, 2, [3, 4, 5])
Error
(1, [3, 4, 5])
(1, 2, [3, 4])
What will 'python'[1:4] return?
'tho'
'pyt'
'yth'
'ytho'
What is the output of the following code? s = 'abcabc' print(s.strip('a'))
bc
abcabc
abc
bcabc
Which collection type maintains insertion order as of Python 3.7+?
Dictionary
List
Tuple
Set
Which of the following is an immutable collection?
Dictionary
Set
Tuple
List
What is the data structure used in breadth-first search (BFS)?
Set
Queue
List
Stack
What does `set([1,2,2,3])` return?
(1,2,3)
{1,2,2,3}
[1,2,3]
{1,2,3}
What will be the output of the following code ?
2 2
3 2
2 3
3 3
s = "automation"
vowels = "aeiou"
result = []
for i in range(len(s)):
if s[i] in vowels:
if i % 2 == 0:
result.append(s[i].upper())
else:
result.append(s[i])
print("".join(result))
uoaiio
uoAiio
Auoaio
AuoAio
