wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Fundamentals Worksheet (Transcribed)

Total questions: 22

Worksheet time: 11mins

Name
Class
Date
1.

What will be the value of the following Python expression? print(4 + 3 % 5)

a)

7

b)

2

c)

4

d)

1

2.

What will be the output of the following Python code? a = 10 def f(): a = 5 f() print(a)

a)

5

b)

10

c)

Error

d)

None

3.

Which of the following statements is true about Python lists?

a)

Lists store elements of same data type

b)

Lists are immutable

c)

Lists can grow dynamically

d)

Lists use contiguous memory only

4.

What is the output of the following code? print(bool([]), bool({}), bool(0))

a)

True True True

b)

False False False

c)

True False True

d)

False True False

5.

Which module is used for regular expressions in Python?

a)

regex

b)

pyregex

c)

re

d)

expression

6.

Which of the following can help find the version of Python currently in use?

a)

sys.version(1)

b)

sys.version(0)

c)

sys.version()

d)

sys.version

7.

Python supports the creation of anonymous functions at runtime using a construct called ________.

a)

pi

b)

anonymous

c)

lambda

d)

none of the mentioned

8.

What will be printed by the following code? x = 10 def func(): global x x = 5 func() print(x)

a)

10

b)

5

c)

Error

d)

None

9.

What is the value of the following Python expression? print(2**3**2)

a)

81

b)

512

c)

12

d)

64

10.

Which data structure does a Python set use internally?

a)

Tree

b)

Stack

c)

Hash table

d)

Queue

11.

What will be the output of the following Python expression if x = 56.236? print("%.2f" % x)

a)

56.236

b)

56.23

c)

56.0000

d)

56.24

12.

Which function is called when the following Python program is executed? f = foo() format(f)

a)

str()

b)

format()

c)

__str__()

d)

__format__()

13.

Which module in the Python standard library parses options received from the command line?

a)

getarg

b)

getopt

c)

main

d)

os

14.

Which keyword is used to create an abstract method?

a)

abstract

b)

@abstractmethod

c)

@virtual

d)

abstractmethod()

15.

Which Python feature supports lazy evaluation?

a)

List

b)

Tuple

c)

Generator

d)

Dictionary

16.

What is the output of the following code? a = 5 b = 5 print(a is b)

a)

True

b)

False

c)

Error

d)

Depends on system

17.

Which of the following raises a StopIteration exception?

a)

range()

b)

list()

c)

Generator

d)

print()

18.

What will be the output of the following code? print(bool("False"))

a)

False

b)

True

c)

Error

d)

None

19.

Which of the following is NOT a Python built‑in function?

a)

sum()

b)

len()

c)

avg()

d)

max()

20.

What will be printed by the following code? print(len("Python"))

a)

5

b)

6

c)

7

d)

8

21.

What will be the output? a = [1, 2, 3] b = a a = a + [4] print(b)

a)

[1, 2, 3, 4]

b)

[1, 2, 3]

c)

Error

d)

[4]

22.

What will be the output? print(True + True * False)

a)

0

b)

1

c)

2

d)

Error