WorksheetsPython Programming Quiz
Total questions: 30
Worksheet time: 15mins
Which operator is used for floor division in Python?
/
%
//
**
What will be the output of "hello".upper()?
Hello
HELLO
hello
HeLLo
Which of the following is immutable?
List
Set
Tuple
Dictionary
What is the result of len({1,2,2,3})?
4
3
2
Error
What does list("abc") return?
("a","b","c")
{"a","b","c"}
["a","b","c"]
"abc"
Which method is used to add an element to a set?
append()
add()
insert()
push()
What is the output of: my_tuple = (10, 20, 30) print(my_tuple[1])
10
20
30
Error
What type is returned by type({})?
set
dict
list
tuple
NumPy arrays are created using which function?
np.array()
np.create()
np.arr()
np.build()
What is the output of np.zeros(3)?
[1,1,1]
[0,0,0]
[None,None,None]
Error
What does range(5) generate?
0 to 5
1 to 5
0 to 4
Only 5
Which of the following is a selection statement?
for
while
if
range
How do you iterate through a dictionary’s keys?
dict.values()
dict.items()
dict.keys()
dict.all()
What is the output? "Python"[2]
t
P
t
y
Which operator checks if two values are equal?
=
==
:=
!=
What is the result of: lst = [10, 20, 30] lst.append(40) print(len(lst))
3
4
5
Error
Which of the following creates a dictionary?
(a,b)
[a,b]
{a,b}
{"a":1, "b":2}
Which loop runs until a condition becomes false?
for
while
if
switch
What is the output of: set([1, 2, 3, 2])
[1,2,3]
{1,2,2,3}
{1,2,3}
Error
What is the type of the result of range(3) in Python 3?
list
tuple
range object
int
What will be the output? a = {1, 2, 3} b = {3, 4, 5} print(a.intersection(b))
{1, 2, 3, 4, 5}
{4, 5}
{3}
[3]
What will be printed? t = (10, 20, 30) x, y, z = t print(y)
10
20
30
Error
Output of the following: s = "python" print(s[::-1])
python
nohtyp
error
['p','y','t','h','o','n']
What is the output? d = {"a":1, "b":2} d["c"] = d["b"] + 3 print(d)
{"a":1, "b":2}
{"a":1, "b":2, "c":3}
{"a":1, "b":2, "c":5}
Error
What will this code display? lst = [1, 2, 3] lst.insert(1, 10) print(lst)
[1, 2, 3, 10]
[10, 1, 2, 3]
[1, 10, 2, 3]
Error
Output of the following: s = {"a", "b", "c"} s.add("a") print(len(s))
4
2
3
Error
What will be printed? t = (1, [2, 3], 4) t[1].append(5) print(t)
(1, [2, 3], 4)
(1, [2, 3, 5], 4)
(1, [5], 4)
Error (tuple cannot change)
Output of: text = "hello world" print(text.replace("l", "*", 2))
heo world
heo word
helo world
he* *o world
What does this print? d = {"a": 1, "b": 2} print(d.get("c", "not found"))
None
Error
not found
c
What will be the output? lst = [1, 2, 3, 4] print([x for x in lst if x % 2 == 0])
[1,3]
[1, 2, 3, 4]
[2, 4]
[4, 2]
