wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

Which operator is used for floor division in Python?

a)

/

b)

%

c)

//

d)

**

2.

What will be the output of "hello".upper()?

a)

Hello

b)

HELLO

c)

hello

d)

HeLLo

3.

Which of the following is immutable?

a)

List

b)

Set

c)

Tuple

d)

Dictionary

4.

What is the result of len({1,2,2,3})?

a)

4

b)

3

c)

2

d)

Error

5.

What does list("abc") return?

a)

("a","b","c")

b)

{"a","b","c"}

c)

["a","b","c"]

d)

"abc"

6.

Which method is used to add an element to a set?

a)

append()

b)

add()

c)

insert()

d)

push()

7.

What is the output of: my_tuple = (10, 20, 30) print(my_tuple[1])

a)

10

b)

20

c)

30

d)

Error

8.

What type is returned by type({})?

a)

set

b)

dict

c)

list

d)

tuple

9.

NumPy arrays are created using which function?

a)

np.array()

b)

np.create()

c)

np.arr()

d)

np.build()

10.

What is the output of np.zeros(3)?

a)

[1,1,1]

b)

[0,0,0]

c)

[None,None,None]

d)

Error

11.

What does range(5) generate?

a)

0 to 5

b)

1 to 5

c)

0 to 4

d)

Only 5

12.

Which of the following is a selection statement?

a)

for

b)

while

c)

if

d)

range

13.

How do you iterate through a dictionary’s keys?

a)

dict.values()

b)

dict.items()

c)

dict.keys()

d)

dict.all()

14.

What is the output? "Python"[2]

a)

t

b)

P

c)

t

d)

y

15.

Which operator checks if two values are equal?

a)

=

b)

==

c)

:=

d)

!=

16.

What is the result of: lst = [10, 20, 30] lst.append(40) print(len(lst))

a)

3

b)

4

c)

5

d)

Error

17.

Which of the following creates a dictionary?

a)

(a,b)

b)

[a,b]

c)

{a,b}

d)

{"a":1, "b":2}

18.

Which loop runs until a condition becomes false?

a)

for

b)

while

c)

if

d)

switch

19.

What is the output of: set([1, 2, 3, 2])

a)

[1,2,3]

b)

{1,2,2,3}

c)

{1,2,3}

d)

Error

20.

What is the type of the result of range(3) in Python 3?

a)

list

b)

tuple

c)

range object

d)

int

21.

What will be the output? a = {1, 2, 3} b = {3, 4, 5} print(a.intersection(b))

a)

{1, 2, 3, 4, 5}

b)

{4, 5}

c)

{3}

d)

[3]

22.

What will be printed? t = (10, 20, 30) x, y, z = t print(y)

a)

10

b)

20

c)

30

d)

Error

23.

Output of the following: s = "python" print(s[::-1])

a)

python

b)

nohtyp

c)

error

d)

['p','y','t','h','o','n']

24.

What is the output? d = {"a":1, "b":2} d["c"] = d["b"] + 3 print(d)

a)

{"a":1, "b":2}

b)

{"a":1, "b":2, "c":3}

c)

{"a":1, "b":2, "c":5}

d)

Error

25.

What will this code display? lst = [1, 2, 3] lst.insert(1, 10) print(lst)

a)

[1, 2, 3, 10]

b)

[10, 1, 2, 3]

c)

[1, 10, 2, 3]

d)

Error

26.

Output of the following: s = {"a", "b", "c"} s.add("a") print(len(s))

a)

4

b)

2

c)

3

d)

Error

27.

What will be printed? t = (1, [2, 3], 4) t[1].append(5) print(t)

a)

(1, [2, 3], 4)

b)

(1, [2, 3, 5], 4)

c)

(1, [5], 4)

d)

Error (tuple cannot change)

28.

Output of: text = "hello world" print(text.replace("l", "*", 2))

a)

heo world

b)

heo word

c)

helo world

d)

he* *o world

29.

What does this print? d = {"a": 1, "b": 2} print(d.get("c", "not found"))

a)

None

b)

Error

c)

not found

d)

c

30.

What will be the output? lst = [1, 2, 3, 4] print([x for x in lst if x % 2 == 0])

a)

[1,3]

b)

[1, 2, 3, 4]

c)

[2, 4]

d)

[4, 2]