
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































Assessment Title: Foundations of Programming in Python Comprehensive Objective Assessment Practice Exam (250 Questions — Batch 1 of 5) Total Question Bank: 250 Multiple-Choice Questions organized into 5 modular batches of 50 questions each (Batch 1 covers Questions 1–50). Question Format: Single-select objective multiple-choice questions featuring 4 distinct options (A, B, C, D), verified correct answers highlighted in bold dark green (#0B6E28), and detailed italicized rationales. Core Competencies Evaluated: Python syntax, dynamic typing, memory references, operators, conditional branching, loop constructs, function design, lexical scoping, built-in collections, file handling, JSON/CSV serialization, exception handling, and fundamental object-oriented programming. Recommended Passing Benchmark: 80% or higher (200+ out of 250 questions) to demonstrate mastery across core Python programming constructs and code tracing.
Domain Core Topic Area Questions Weight Batch Mapping Domain 1 Variables, Data Types, Expressions & Operators 40 16% Q1 – Q40 (Batch 1) Domain 2 Control Flow, Conditional Logic & Iteration 35 14% Q41 – Q75 (Batches 1 – 2) Domain 3 Functions, Scope, Closures & Standard Modules 40 16% Q76 – Q115 (Batches 2 – 3) Domain 4 Built-In Data Structures (Lists, Tuples, Sets, Dicts) 45 18% Q116 – Q (Batches 3–4) Domain 5 File I/O, Context Managers & Data Serialization 30 12% Q161 – Q190 (Batch
Domain 6 Exception Handling, Testing & Code Debugging 30 12% Q191 – Q (Batches 4–5) Domain 7 Basic Object-Oriented Programming (Classes & Methods) 30 12% Q221 – Q250 (Batch
TOTAL Complete Python Programming Objective Assessment 250 100% Batches 1 – 5
Simulate Timed Assessment Conditions: Complete each 50-question batch within 60 to 75 minutes without running code in an interpreter first. Trace variable states, loop iterations, and object mutations manually on scratch paper.
Analyze Distractors & Edge Cases: Review the italicized rationale beneath every question to understand not only why the green-highlighted option is right, but why the distractors trigger TypeError, IndexError, KeyError, or subtle logic bugs. Track Domain Readiness: Record your score per domain against the Content Blueprint weights. Revisit any domain scoring below 80% before attempting the next 50-question batch.
Question 5 [Domain 1: Variables, Data Types & Operators] Which expression evaluates to True in Python? A. bool('False') [CORRECT ANSWER] B. bool(0.0) C. bool([]) D. bool(None) Rationale: Any non-empty string—including 'False'—is truthy in Python and evaluates to True when passed to bool(). Zero numeric values (0.0), empty containers ([]), and None are falsy. Question 6 [Domain 1: Variables, Data Types & Operators] What is the difference between the == operator and the is operator in Python? A. == compares memory addresses, whereas is compares object values B. == compares object values for equality, whereas is tests object identity (same memory address) [CORRECT ANSWER] C. == works only on numeric types, whereas is works only on strings D. There is no functional difference between == and is in Python 3 Rationale: The equality operator (==) invokes eq() to evaluate whether two objects have equivalent values, whereas the identity operator (is) checks whether both operands refer to the exact same object in memory (id(a) == id(b)). Question 7 [Domain 1: Variables, Data Types & Operators] What is the result of evaluating 2 ** 3 ** 2 in Python? A. 64 B. 512 [CORRECT ANSWER] C. 36 D. 12 Rationale: _The exponentiation operator (**) is right-associative in Python. Therefore, 2 ** 3 ** 2 is evaluated as 2 ** (3 **
Question 9 [Domain 1: Variables, Data Types & Operators] What does the expression 'abcdef'[1:5:2] return? A. 'bd' [CORRECT ANSWER] B. 'bdf' C. 'ce' D. 'bcde' Rationale: String slicing [start:stop:step] starts at index 1 ('b'), stops before index 5 ('f'), and advances by a step of 2, selecting indices 1 ('b') and 3 ('d') to yield 'bd'. Question 10 [Domain 1: Variables, Data Types & Operators] Which built-in function returns the Unicode code point (integer) of a single character string such as 'A'? A. chr('A') B. ord('A') [CORRECT ANSWER] C. ascii('A') D. hex('A') Rationale: ord('A') returns the integer Unicode code point 65, while chr(65) performs the inverse operation by converting an integer code point back into a single-character string. Question 11 [Domain 1: Variables, Data Types & Operators] What is the result of the expression 0.1 + 0.2 == 0.3 in Python? A. True B. False [CORRECT ANSWER] C. TypeError D. ValueError Rationale: Because standard binary floating-point numbers (IEEE 754 double precision) cannot represent 0.1 and 0. exactly in base 2, 0.1 + 0.2 evaluates to 0.30000000000000004, making == 0.3 evaluate to False. Question 12 [Domain 1: Variables, Data Types & Operators] Which of the following types is IMMUTABLE in Python? A. list B. dict C. set D. tuple [CORRECT ANSWER] Rationale: Tuples, strings, integers, floats, booleans, and frozensets are immutable in Python. Lists, dictionaries, and sets are mutable collections. Question 13 [Domain 1: Variables, Data Types & Operators] What does the expression int('1010', 2) return? A. 1010 B. 10 [CORRECT ANSWER] C. 20 D. ValueError Rationale: Passing a second argument to int(x, base) parses the string x in the specified number base. Binary '1010' equals 1(8) + 0(4) + 1(2) + 0(1) = 10 in base 10.
Question 18 [Domain 1: Variables, Data Types & Operators] Which statement accurately describes Python's dynamic typing system? A. Variables have fixed static types determined at compile time, while objects are untyped B. Type annotations (e.g., x: int = 'hi') raise a TypeError at runtime C. Objects carry type information at runtime, and variable names can be rebound to objects of any type [CORRECT ANSWER] D. Python automatically converts strings to integers during + addition Rationale: Python is dynamically and strongly typed: objects have concrete types at runtime, names can be rebound to any object, and invalid cross-type operations like '5' + 3 raise TypeError rather than implicitly coercing. Question 19 [Domain 1: Variables, Data Types & Operators] What is the output of print(' hello world '.strip().title())? A. ' Hello World ' B. 'Hello World' [CORRECT ANSWER] C. 'Hello world' D. 'HELLO WORLD' Rationale: .strip() removes leading and trailing whitespace to produce 'hello world', and .title() capitalizes the first letter of each word, yielding 'Hello World'. Question 20 [Domain 1: Variables, Data Types & Operators] What value does the expression 15 % 4 produce? A. 3 [CORRECT ANSWER] B. 3. C. 1 D. 0 Rationale: The modulo operator (%) returns the remainder of integer division. Since 15 = 3 * 4 + 3, 15 % 4 evaluates to 3. Question 21 [Domain 1: Variables, Data Types & Operators] Which bitwise operator performs a bitwise XOR (exclusive OR) on two integers in Python? A. & B. | C. ^ [CORRECT ANSWER] D. ~ Rationale: In Python, ^ is the bitwise XOR operator, & is bitwise AND, | is bitwise OR, and ~ is bitwise NOT (one's complement).
Question 22 [Domain 1: Variables, Data Types & Operators] What happens when you run the following statement? a, b, c = [1, 2, 3, 4, 5] A. SyntaxError: invalid syntax B. a = 1, b = 2, c = [3, 4, 5] [CORRECT ANSWER] C. a = 1, b = 2, c = (3, 4, 5) D. ValueError: too many values to unpack Rationale: _Extended iterable unpacking (c) captures any remaining unpacked elements into a standard Python list, so a=1, b=2, and c=[3, 4, 5]._ Question 23 [Domain 1: Variables, Data Types & Operators] What is the output of print('Py' * 3 + '!' * 0)? A. PyPyPy! B. PyPyPy [CORRECT ANSWER] C. TypeError D. Py3! Rationale: Multiplying a string by a positive integer n repeats it n times ('PyPyPy'), while multiplying a string by 0 or a negative integer produces an empty string (''). Question 24 [Domain 1: Variables, Data Types & Operators] Which expression checks whether the variable val is None according to PEP 8 best practices? A. val == None B. val is None [CORRECT ANSWER] C. isinstance(val, None) D. type(val) == None Rationale: Because None is a singleton object in Python, PEP 8 mandates testing for None using identity comparison (val is None or val is not None) rather than ==. Question 25 [Domain 1: Variables, Data Types & Operators] What does 'data_2026.csv'.removesuffix('.csv') return in Python 3.9+? A. 'data_2026' [CORRECT ANSWER] B. 'data_2026.' C. 'data_2026.csv' D. AttributeError Rationale: str.removesuffix('.csv') removes the exact trailing substring '.csv' if present and returns 'data_2026', unlike rstrip('.csv') which strips any individual character in the set {'.', 'c', 's', 'v'}.
Question 30 [Domain 1: Variables, Data Types & Operators] What is the output of the following code? x = 10 x += 5 * 2 print(x) A. 30 B. 20 [CORRECT ANSWER] C. 25 D. 17 Rationale: In an augmented assignment statement (x += expr), the entire right-hand side expression (5 * 2 = 10) is evaluated first before adding to x (10 + 10 = 20). Question 31 [Domain 1: Variables, Data Types & Operators] What does '-'.join(['2026', '11', '24']) evaluate to? A. '2026- 11 - 24' [CORRECT ANSWER] B. '- 2026 - 11 - 24 - ' C. TypeError D. ['2026- 11 - 24'] Rationale: The separator string's .join(iterable) method concatenates all string elements in the iterable with '-' placed between adjacent items, producing '2026- 11 - 24'. Question 32 [Domain 1: Variables, Data Types & Operators] What happens if you pass a list of integers [1, 2, 3] to ', '.join([1, 2, 3])? A. Returns '1, 2, 3' B. Raises TypeError: sequence item 0: expected str instance, int found [CORRECT ANSWER] C. Returns '[1, 2, 3]' D. Raises ValueError Rationale: str.join() requires every element in the iterable to already be a str instance; it does not implicitly convert integers and raises a TypeError. Question 33 [Domain 1: Variables, Data Types & Operators] What is the value of len('a\nb\tc')? A. 7 B. 5 [CORRECT ANSWER] C. 6 D. 8 Rationale: Escape sequences \n (newline) and \t (tab) each represent a single character in memory, so 'a', '\n', 'b', '\t', 'c' has a total length of 5.
Question 34 [Domain 1: Variables, Data Types & Operators] Which statement swaps the values of variables x and y in a single Pythonic line without a temporary variable? A. x, y = y, x [CORRECT ANSWER] B. x <-> y C. swap(x, y) D. x = y; y = x Rationale: Tuple packing and unpacking (x, y = y, x) evaluates the right-hand tuple (y, x) completely before unpacking its elements into x and y simultaneously. Question 35 [Domain 1: Variables, Data Types & Operators] What does 'Mississippi'.rfind('ss') return? A. 2 B. 5 [CORRECT ANSWER] C. 6 D. - 1 Rationale: str.rfind(sub) searches from the right and returns the highest starting index where substring 'ss' is found, which is index 5 (whereas .find('ss') returns 2). Question 36 [Domain 1: Variables, Data Types & Operators] What is the difference between str.find('z') and str.index('z') when 'z' is NOT present in the string? A. Both return - 1 B. find() returns - 1, whereas index() raises ValueError [CORRECT ANSWER] C. find() raises ValueError, whereas index() returns None D. Both raise IndexError Rationale: str.find() returns - 1 when a substring is not found, making it safe for conditional checks, whereas str.index() raises a ValueError exception. Question 37 [Domain 1: Variables, Data Types & Operators] What does isinstance(True, int) evaluate to in Python? A. False B. True [CORRECT ANSWER] C. TypeError D. None Rationale: In Python, bool is a subclass of int (where True == 1 and False == 0), so isinstance(True, int) evaluates to True. Question 38 [Domain 1: Variables, Data Types & Operators] What is the output of print(not True or False and True)? A. True B. False [CORRECT ANSWER] C. None D. SyntaxError Rationale: Boolean operator precedence from highest to lowest is: not, then and, then or. Thus (not True) or (False and True) evaluates to False or False, which is False.
if n == 4: break print(n, end='') A. 01234 B. 0124 C. 012 [CORRECT ANSWER] D. 0123 Rationale: For n=0, 1, 2 it prints '012'. At n=3, continue skips print(n) and advances to n=4. At n=4, break immediately exits the loop before printing. Question 44 [Domain 2: Control Flow & Iteration] Which built-in function allows you to iterate over a sequence while simultaneously receiving both the index and the element value? A. zip() B. enumerate() [CORRECT ANSWER] C. iter() D. range() Rationale: enumerate(iterable, start=0) yields (index, item) pairs on each iteration, eliminating manual counter variables. Question 45 [Domain 2: Control Flow & Iteration] What happens when zip([1, 2, 3], ['a', 'b']) is converted to a list using list(...) by default? A. [(1, 'a'), (2, 'b'), (3, None)] B. [(1, 'a'), (2, 'b')] [CORRECT ANSWER] C. ValueError: zip() arguments have different lengths D. [(1, 'a'), (2, 'b'), (3, '')] Rationale: By default (strict=False), zip() stops as soon as the shortest input iterable is exhausted, producing [(1, 'a'), (2, 'b')]. Passing strict=True raises ValueError. Question 46 [Domain 2: Control Flow & Iteration] What is the output of the following conditional expression? score = 72 status = 'Pass' if score >= 75 else 'Retake' if score >= 60 else 'Fail' print(status) A. Pass B. Retake [CORRECT ANSWER] C. Fail D. SyntaxError Rationale: Chained conditional expressions evaluate left-to-right: score >= 75 is False, so it evaluates the else branch ('Retake' if score >= 60 else 'Fail'), which evaluates to 'Retake'.
Question 47 [Domain 2: Control Flow & Iteration] What is the purpose of the pass statement in Python? A. To skip the current iteration of a loop and move to the next one B. To exit a function immediately and return None C. To act as a syntactic no-operation placeholder where a statement is required [CORRECT ANSWER] D. To suppress all exceptions raised inside a block Rationale: pass is a null operation used when Python syntax requires an indented block (such as an empty function, class, or conditional branch) that has no implementation yet. Question 48 [Domain 2: Control Flow & Iteration] What is the output of the following code? count = 0 while count < 3: count += 1 else: print('Done:', count) A. Done: 2 B. Done: 3 [CORRECT ANSWER] C. Nothing is printed D. Infinite loop Rationale: The loop increments count to 1, 2, and 3. When count reaches 3, count < 3 becomes False without a break, so the else block executes and prints 'Done: 3'. Question 49 [Domain 2: Control Flow & Iteration] In Python 3.10+, which keyword serves as the wildcard catch-all pattern in a structural pattern matching match/case block? A. default: B. else: C. case _: [CORRECT ANSWER] D. case *: Rationale: _In Python's match/case statement, case : acts as the irrefutable wildcard pattern that matches any subject not matched by preceding cases. Question 50 [Domain 2: Control Flow & Iteration] Why is modifying (such as removing elements from) a list while iterating directly over that same list in a for loop generally discouraged? A. Python immediately raises RuntimeError: list changed size during iteration B. Removing an element shifts subsequent indices left, causing the loop iterator to skip the next element [CORRECT ANSWER] C. It permanently locks the list in read-only mode D. It automatically reverses the order of remaining items Rationale: Unlike dictionaries and sets (which raise RuntimeError on size change during iteration), lists advance an internal index counter; deleting an item shifts remaining items left, silently skipping elements.
Question 54. Which statement immediately skips the remaining code in the current loop iteration and jumps to the next iteration? A. break B. pass C. continue [CORRECT ANSWER] D. return Rationale: continue aborts the remainder of the current iteration and proceeds directly to the next iteration's condition/item check, whereas break terminates the entire loop and pass is a null operation. Question 55. What is the output of the following nested loop snippet? count = 0 for i in range(3): for j in range(i): count += 1 print(count) A. 6 B. 3 [CORRECT ANSWER] C. 9 D. 0 Rationale: When i=0, range(0) runs 0 times; when i=1, range(1) runs 1 time (j=0); when i=2, range(2) runs 2 times (j=0, 1). Total increments = 0 + 1 + 2 = 3. Question 56. What happens if you modify a list by removing elements while iterating directly over that same list with a for item in items: loop? A. Python raises a RuntimeError: list changed size during iteration. B. Elements immediately following a removed element are skipped because internal indices shift left. [CORRECT ANSWER] C. Python automatically creates a shallow copy of the list before starting the loop. D. The loop restarts from index 0 after every deletion. Rationale: Unlike dictionaries and sets (which raise RuntimeError), Python lists advance an internal integer index on each step. Removing an item shifts subsequent items left by one index, causing the next element to be skipped. Question 57. Which built-in function allows you to iterate over two or more sequences in parallel, stopping when the shortest iterable is exhausted? A. enumerate() B. zip() [CORRECT ANSWER] C. map() D. iter() Rationale: zip(iter1, iter2, ...) pairs corresponding elements from each iterable into tuples and stops as soon as the shortest input iterable ends (unless strict=True is specified). Question 58. What is the output of the following code using enumerate?
colors = ['red', 'green'] for idx, val in enumerate(colors, start=1): print(f'{idx}:{val}', end=' ') A. 0:red 1:green B. 1:red 2:green [CORRECT ANSWER] C. red:1 green: D. TypeError: enumerate() takes at most 1 argument Rationale: enumerate(iterable, start=1) yields (index, value) tuples beginning the counter at 1 rather than the default 0, producing 1:red 2:green. Question 59. Which Python statement acts as a syntactic placeholder when a block is required by grammar (such as inside an empty if or while body) without performing any action? A. continue B. None C. pass [CORRECT ANSWER] D. skip Rationale: pass is Python's no-op statement used to satisfy indentation syntax rules where a suite of statements is required. Question 60. What is the value of result after executing this conditional expression (ternary operator)? score = 72 result = 'Pass' if score >= 75 else 'Retry' if score >= 60 else 'Fail' A. 'Pass' B. 'Retry' [CORRECT ANSWER] C. 'Fail' D. SyntaxError Rationale: Chained conditional expressions evaluate right-associatively: score >= 75 is False, so it evaluates 'Retry' if score >= 60 else 'Fail', which is True (72 >= 60) and returns 'Retry'. Question 61. What is the output of the following while loop? n = 4 while n > 0: n - = 1 if n == 2: continue print(n, end=' ') A. 4 3 1 0 B. 3 1 0 [CORRECT ANSWER] C. 3 2 1 0 D. 3 1 Rationale: n is decremented before printing: when n=4 - > n=3 (prints 3); n=3 - > n=2 (continue skips print); n=2 - > n=1 (prints 1); n=1 - > n=0 (prints 0). Output is 3 1 0.
Question 66. What happens if you pass a floating-point number to range(), such as range(0, 5, 0.5)? A. It generates [0.0, 0.5, 1.0, ..., 4.5]. B. It truncates 0.5 to 0 and enters an infinite loop. C. It raises a TypeError: 'float' object cannot be interpreted as an integer. [CORRECT ANSWER] D. It rounds 0.5 to 1 and generates [0, 1, 2, 3, 4]. Rationale: Python's built-in range() strictly requires integer arguments for start, stop, and step; passing a float raises a TypeError. Question 67. Which pattern in Python structural pattern matching (match/case) matches any subject value without binding it to a variable name? A. case *: B. case default: C. case _: [CORRECT ANSWER] D. case None: Rationale: The single underscore _ acts as the irrefutable wildcard pattern in match/case, matching any value without assigning it to a variable. Question 68. What is the output of the following code? items = [1, 2, 3] total = 0 while items: total += items.pop() print(total, len(items)) A. 6 0 [CORRECT ANSWER] B. 6 3 C. 0 0 D. IndexError Rationale: A non-empty list is truthy. Each iteration pops and adds the last element (3 + 2 + 1 = 6) until items is empty ([]), which is falsy and terminates the loop with len(items) == 0. Question 69. What does any([0, '', None, 42, []]) return? A. 42 B. True [CORRECT ANSWER] C. False D. None Rationale: any(iterable) returns the boolean True as soon as it encounters at least one truthy element (42), short-circuiting the remainder of the iterable.
Question 70. What does all([]) (passing an empty list to all()) return in Python? A. False B. True [CORRECT ANSWER] C. None D. ValueError Rationale: By vacuous truth in predicate logic, all(iterable) returns True when the iterable is empty because there are no falsy elements present. Question 71. In a for loop iterating over a dictionary d = {'a': 1, 'b': 2} via for x in d:, what values are assigned to x? A. Tuples of ('a', 1) and ('b', 2) B. The dictionary values 1 and 2 C. The dictionary keys 'a' and 'b' [CORRECT ANSWER] D. A TypeError is raised because dictionaries are not directly iterable Rationale: Iterating directly over a dictionary yields its keys in insertion order. To iterate over values or key- value pairs, you must call .values() or .items(). Question 72. What is the output of the following code? for i in range(3): pass print(i) A. NameError: name 'i' is not defined B. 2 [CORRECT ANSWER] C. 3 D. None Rationale: In Python, for loops do not create a new local scope. After the loop finishes its final iteration (i = 2), the loop variable i remains bound to 2 in the enclosing scope. Question 73. Which control flow construct ensures that break inside an inner loop exits ONLY the inner loop rather than all enclosing loops? A. Python's default behavior: break always exits only the innermost enclosing loop. [CORRECT ANSWER] B. Using break 1 to specify single-level exit. C. Placing a pass statement immediately after the inner loop. D. Wrapping the inner loop in an if block. Rationale: In Python, break and continue always apply strictly to the nearest enclosing for or while loop.