Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Final Exam Sample Q & A – Extracted Questions

Total questions: 16

Worksheet time: 18mins

Name
Class
Date
1.

For each statement in Column 1, answer T (true) or F (false). Python’s built-in functional programming tools do not modify the input data.

a)

True

b)

False

2.

For each statement in Column 1, answer T (true) or F (false). The Python re.search() function will find all non-overlapping matches of a pattern within a string.

a)

True

b)

False

3.

For each statement in Column 1, answer T (true) or F (false). A Python list comprehension is faster than an equivalent Python for loop.

a)

True

b)

False

4.

For each statement in Column 1, answer T (true) or F (false). In production applications, Python logging() is generally preferred over Python print().

a)

True

b)

False

5.

Multiple-choice questions. There is only 1 correct choice. What keyword is used to create a generator function?

a)

return

b)

yield

c)

next

d)

lambda

e)

None of the above

6.

Multiple-choice questions. There is only 1 correct choice. Which regex function returns a match only if the pattern occurs at the beginning of a string?

a)

re.search()

b)

re.findall()

c)

re.fullmatch()

d)

re.match()

e)

re.sub()

7.

Multiple-choice questions. There is only 1 correct choice. Which of the following is a valid Python list comprehension?

a)

lc = [x * 2 for x in range(5) if x = 3]

b)

lc = (x * 2 for x in range(5))

c)

lc = [x * 2 for x in range(5)]

d)

lc = {x * 2 for x in range(5)}

e)

lc = list(x * 2 for x in range(5))

8.

What is one key advantage of using logging instead of print() for debugging?

a)

Logging messages can be filtered by severity level

b)

Logging automatically fixes syntax errors

c)

Logging runs twice as fast as print statements

d)

Logging only works in production environments

e)

Logging requires no configuration

9.

Part 3: Short answer questions. Please give brief answers (At most, 1-2 sentences per question). What is a Python iterator?

4 lines
10.

Part 3: Short answer questions. Please give brief answers (At most, 1-2 sentences per question). What does the Python filter() function do, and what does it return?

4 lines
11.

Part 3: Short answer questions. Please give brief answers (At most, 1-2 sentences per question). What does the Python assert statement do?

4 lines
12.

Part 3: Short answer questions. Please give brief answers (At most, 1-2 sentences per question). In Python object-oriented programming (OOP), what is a class?

4 lines
13.

Part 4: Code-tracing questions. For each question, trace the code and write the exact output. If the code does not produce any output, write "No output". If the code produces an error (exception), write "Exception". What is the output of this code? data = [1,2,3,4] result = list(map(lambda x: x * 10, data)) print(result[1])

(a)  

14.

Part 4: Code-tracing questions. For each question, trace the code and write the exact output. If the code does not produce any output, write "No output". If the code produces an error (exception), write "Exception". What is the output of this code? import numpy as np nums = np.arange(100,250,50) it = iter(nums) next(it) next(it) next(it) print(next(it))

(a)  

15.

Part 4: Code-tracing questions. For each question, trace the code and write the exact output. If the code does not produce any output, write "No output". If the code produces an error (exception), write "Exception". What is the output of this code? cities = ['New York', 'Chicago', 'Philadelphia', 'Boston'] sorted(cities, key=len, reverse=True) print(cities)

(a)  

16.

Part 4: Code-tracing questions. For each question, trace the code and write the exact output. If the code does not produce any output, write "No output". If the code produces an error (exception), write "Exception". What is the result of the following code? fruits_1 = ['apple', 'banana', 'pear', 'kiwi'] fruits_2 = {w: len(w) for w in fruits_1 if len(w) <= 4} print(fruits_2)

(a)