2023 Python Practice Exam: 439 Fill‑in, 298 True/False, 32 Short Answer Questions

A comprehensive collection of 2023 Python practice questions—including fill‑in‑the‑blank, true/false, and short‑answer items—covers topics from multimedia and database programming to threading, networking, GUI, exception handling, file I/O, OOP, and core language features, with sample code snippets for deeper understanding.

Liangxu Linux
Liangxu Linux
Liangxu Linux
2023 Python Practice Exam: 439 Fill‑in, 298 True/False, 32 Short Answer Questions

Python Practice Exam 2023

This resource provides a large set of Python practice questions designed for learners ranging from beginners to advanced users. It includes 439 fill‑in‑the‑blank items, 298 true/false statements, and 32 short‑answer questions, covering a wide spectrum of programming topics.

Covered Topics

Multimedia programming

Database programming

Multithreading

Network programming

GUI development

Exception handling structures

File operations

Object‑oriented design

Function definition and usage

String and regular expressions

Selection and loop structures

Python sequences

Fundamental language concepts

Sample Fill‑in‑the‑Blank Questions

5. The complete pip command to upgrade the scientific‑computing library numpy is __________.

10. The built‑in Python function that returns the type of a variable is __________.

24. The built‑in function that can return the number of elements in a list, tuple, dictionary, set, string, or range object is __________.

53. Given a = ['name', 'age', 'sex'] and b = ['Dong', 38, 'Male'], write a single statement that creates a dictionary using elements of a as keys and elements of b as values: __________.

57. For a = [1, 2, 3] and b = [1, 2, 4], the result of id(a[1]) == id(b[1]) is __________.

69. The dictionary method that retrieves a value for a given key and returns a default (or None if unspecified) when the key is absent is __________.

86. The value of the list comprehension

[index for index, value in enumerate([3,5,7,3,7]) if value == max([3,5,7,3,7])]

is __________.

131. In the random module, the function that randomly shuffles a list is __________.

244. For x = {'a':'b', 'c':'d'}, the expression 'b' in x evaluates to __________.

265. The result of ''.join(list('hello world!')) is __________.

284. The value of 'abcabcabc'.rindex('abc') is __________.

306. With x = 'a234b123c' and the re module imported, the result of re.split('\d+', x) is __________.

310. The output of print(re.match('abc', 'defg')) is __________.

353. The GBK encoding uses __________ bytes to represent a Chinese character.

363. After importing the standard library string, the value of len(string.digits) is __________.

390. For g = lambda x, y=3, z=5: x*y*z, the output of print(g(1)) is __________.

409. The expression isinstance('4', (int, float, complex)) evaluates to __________.

423. The context‑manager keyword that automatically handles resource closing regardless of how the block exits is __________.

434. The Python extension library that wraps almost all Windows API functions is __________.

True/False Questions

273. If a file readme.txt has read‑only attributes, executing os.chmod('readme.txt', 0o777) will remove the read‑only attribute.

281. Because the finally block in a try...except...finally construct always runs, placing file‑closing code there guarantees the file is closed without raising any exception.

282. In GUI design, checkboxes are typically used for non‑mutually exclusive multiple selections, and each checkbox operates independently.

286. Using the TCP protocol requires establishing a connection, transmitting data, and then closing the connection.

290. A subclass derived from threading.Thread may not contain ordinary instance methods.

Short‑Answer Questions

Briefly explain Python’s value‑based automatic memory‑management mechanism.

List the two functions of the Python operator &.

Why should list growth and deletion operations preferably be performed at the tail end?

What is the difference between an exception and an error?

What are the main usages of the pdb module for debugging Python programs?

Read the following code and discuss potential problems if the file D:\test.txt does not exist.

Code Examples

Code 1:

try:
    fp = open(r'd:\test.txt')
    print('Hello world!', file=fp)
finally:
    fp.close()

Code 2:

try:
    fp = open(r'd:\test.txt', 'a+')
    print('Hello world!', file=fp)
finally:
    fp.close()

Renaming all .html files to .htm in the current directory:

import os
file_list = os.listdir('.')
for filename in file_list:
    pos = filename.rindex('.')
    if filename[pos+1:] == 'html':
        newname = filename[:pos+1] + 'htm'
        os.rename(filename, newname)
        print(filename + ' renamed to ' + newname)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonPracticequestionsexamfill-in-the-blankshort answertrue/false
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.