
















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!

















Description: Maximize your Python exam score with our definitive 2026/2027 practice paper. This comprehensive guide features 60 essential questions with detailed explanations covering syntax, semantics, data structures, operators, and advanced concepts. Perfect for university students and coding bootcamp prep. Download your free key to programming success today!
Section 1: Programming Language Theory & Execution
1. Which of the following best defines syntax in the context of a programming language? A) The meaning and logical validity of statements within a program. B) The set of reserved words available in the language's dictionary. C) The formal rules governing the structure of valid statements. D) The process of converting source code into machine code. Answer: C Explanation: Syntax refers to the formal, rule-based structure that defines how symbols and keywords must be arranged to form correct statements in a language, analogous to grammar in natural language. 2. The primary distinction between an interpreter and a compiler is: A) An interpreter generates a standalone executable file, while a compiler executes code line-by- line. B) An interpreter translates and executes code line-by-line in real-time, while a compiler translates the entire source code once into machine code. C) Compilers are only used for high-level languages, while interpreters are used for low-level languages. D) Compiled languages are always faster and more efficient than interpreted languages. Answer: B Explanation: An interpreter directly executes instructions from the source code without a separate compilation step, reading and translating code sequentially. A compiler performs a one- time translation of the entire source code into an executable machine code file. 3. What is the role of semantics in programming? A) It ensures the program's statements are structurally correct. B) It defines the vocabulary of reserved keywords. C) It governs whether a syntactically correct statement has a meaningful, logical outcome. D) It manages the indentation and grouping of code blocks.
python if True: print("Hello") print("World") D) python if True print("Hello") print("World") Answer: B Explanation: Python uses indentation (consistent leading whitespace) to define blocks of code. Option B shows correct and consistent indentation for the if block. A lacks indentation, C has inconsistent indentation, and D is missing the colon.
6. The expression 0b1010 + 0xE evaluates to which decimal value? A) 28 B) 24 C) 30 D) 18 Answer: B Explanation: 0b1010 is binary for decimal 10. 0xE is hexadecimal for decimal 14. Their sum is
7. What is the primary characteristic of a Python tuple that distinguishes it from a list? A) Tuples can only contain numeric data. B) Tuples are unordered collections. C) Tuples are immutable sequences. D) Tuples use curly braces {} for definition.
Answer: C Explanation: The defining feature of a tuple is its immutability; its contents cannot be altered after creation. Lists are mutable. Both are ordered sequences. Section 3: Python Operators & Basic Functions
8. What is the output of the following Python operation: - 17 // 4? A) - 4. B) - 4 C) - 5 D) 4 Answer: C Explanation: The floor division operator // returns the largest integer less than or equal to the result. - 17 / 4 = - 4.25. The integer less than or equal to - 4.25 is - 5. 9. Given the statement result = 2 ** 3 ** 2, what is the value of result? A) 64 B) 512 C) 36 D) 12 Answer: B Explanation: The exponentiation operator (**) has right-to-left associativity. Therefore, 3 ** 2 is evaluated first, yielding 9. Then 2 ** 9 is calculated, resulting in 512. 10. What will be the data type of the variable user_data after executing user_data = input("Enter a number: ") if the user types 123? A) Integer (int) B) Floating-point number (float) C) String (str) D) Boolean (bool)
Answer: D Explanation: A set is an unordered, mutable collection that only contains unique elements. Its elements must be of an immutable type (e.g., numbers, strings, tuples).
14. Given the list my_list = [10, 20, 30, 40, 50], what does my_list.index(30) return? A) 2 B) 3 C) 30 D) True Answer: A Explanation: The .index() method returns the position (index) of the first occurrence of the specified value within the list. Indices in Python start at 0, so the value 30 is at index 2. 15. What is the result of the expression: "C" in {"A": 1, "B": 2, "C": 3}? A) True B) False C) 3 D) A KeyError is raised. Answer: A Explanation: The in operator, when used on a dictionary by default, checks for the presence of a key. Since "C" is a key in the dictionary, the expression evaluates to True. 16. Which statement about Python's scientific notation is correct? A) The character separating the mantissa and exponent must be a lowercase 'e'. B) The expression 1.23E- 7 is equivalent to 0.000000123. C) Scientific notation can only be used with integer literals. D) E7 is a valid shorthand for 10**7. Answer: B Explanation: In Python's scientific notation (e.g., 1.23E- 7 ), E or e can be used. 1.23E- 7 means 1.23 multiplied by 10 to the power of - 7, which equals 0.000000123.
17. The escape sequence \n within a string literal is used to: A) Insert a backslash character. B) Ignore the following character. C) Represent a newline character, causing line breaks in output. D) Convert a number to a string. Answer: C Explanation: The backslash () is an escape character. Combined with n, it forms the newline escape sequence \n, which instructs the output to move to the beginning of the next line. Section 5: Boolean Logic and Program Flow 18. Which of the following is a valid Boolean expression in Python? A) value = yes B) result = 10 > 9 C) flag = "True" D) check = 5 + True Answer: B Explanation: A Boolean expression evaluates to either True or False. The comparison 10 > 9 is a valid Boolean expression that evaluates to True. Option C is a string, and D, while potentially valid due to Python's True having an integer value of 1, is an arithmetic expression. 19. What is the output of print(not (5 <= 3) and (10 % 3 == 1))? A) True B) False C) 1 D) 0 Answer: A Explanation: Evaluate stepwise: (5 <= 3) is False. not False is True. (10 % 3 == 1) evaluates as 1 == 1, which is True. The final expression is True and True, which equals True.
23. What will the len() function return for the following tuple: ( (1, 2), [3, 4], {5, 6} )? A) 6 B) 3 C) 1 D) An error, as it contains mixed types. Answer: B Explanation: The len() function returns the number of top-level items in a sequence or collection. The tuple contains three items: a tuple, a list, and a set. It does not recursively count the inner elements. 24. In the context of assignment operators, what is the final value of x after executing: x = 5; x **= 2? A) 10 B) 25 C) 7 D) 52 Answer: B Explanation: The compound assignment operator **= performs exponentiation and assignment. x **= 2 is equivalent to x = x ** 2. Since x is initially 5, 5 ** 2 = 25. 25. A variable defined inside a function is typically known as: A) A global variable. B) A local variable. C) A static variable. D) A keyword. Answer: B Explanation: A variable declared inside a function has a local scope. It is only accessible within that function and ceases to exist once the function execution is complete, unless explicitly returned.
Section 7: Number Systems and Representations
26. The literal 0o755 in Python represents a number in which base? A) Binary (base-2) B) Decimal (base-10) C) Octal (base-8) D) Hexadecimal (base-16) Answer: C Explanation: The prefix 0o (zero followed by the letter 'o') denotes an octal (base-8) literal in Python. Valid octal digits are 0 through 7. 27. Which of the following is an invalid integer literal in Python? A) 1_000_ B) 0b C) 0x1A2F D) 0o Answer: B Explanation: Option B, 0b102, is invalid. The prefix 0b indicates a binary literal, but the digit 2 is not a valid binary digit (only 0 and 1 are allowed). 28. What is the decimal equivalent of the floating-point literal 3.14e- 2? A) 314. B) 0. C) 31. D) 0. Answer: B Explanation: The expression 3.14e- 2 means 3.14 × 10⁻². 10⁻² = 0.01. Therefore, 3.14 × 0.01 = 0.0314.
31. What does this code print? python result = 2 + 3 * 4 ** 2 // 5 print(result) A) 16 B) 14 C) 11 D) 10 Answer: C Explanation: Follow operator precedence: Exponentiation (**) is highest, then Multiplication/Division/Floor Division/Modulo (left to right), then Addition/Subtraction.
Answer: B Explanation: Strings are immutable. When y = x is executed, y references the same string object "Hello". Later, x = x + " World" creates a new string object "Hello World" and reassigns x to it. y remains bound to the original "Hello" object. Section 9: Core Definitions and Concepts
33. The complete set of words reserved for special use and that cannot be used as identifiers (variable names) is called: A) Semantics B) Lexis C) Syntax D) Keywords Answer: D Explanation: Keywords (or reserved words) are words that have a predefined, fixed meaning in the Python language (e.g., if, for, while, True, def). They form a core part of the language's lexis but are specifically prohibited from being used as variable, function, or class names. 34. A data structure that stores mappings of unique keys to values is a: A) List B) Tuple C) Dictionary D) Set Answer: C Explanation: A dictionary (dict) is an unordered, mutable collection that stores data in key- value pairs. Keys must be unique and of an immutable type, allowing for efficient value retrieval based on the key. 35. The process where a source program is translated once into an executable machine code file is called: A) Interpreting B) Compilation
C) Halt execution and report the error with its location. D) Execute all lines preceding line 5 and then stop. Answer: C Explanation: A syntax error indicates code that violates Python's grammatical rules. Since the program structure is invalid, the interpreter cannot proceed. It will stop and generate a traceback message pointing to the location and nature of the error.
39. Which data type would be most appropriate to store a collection of unique customer IDs where order does not matter? A) List B) Tuple C) Dictionary D) Set Answer: D Explanation: A Set is the ideal choice for storing a collection of unique items where membership testing is important and the order of elements is irrelevant. It automatically enforces uniqueness and provides highly efficient membership checks (in operations). 40. The expression bool("False") will evaluate to: A) False B) True C) An error, due to type mismatch. D) "False" Answer: B Explanation: The bool() constructor checks for truthiness. For strings, any non-empty string is considered truthy (True). The string "False" is non-empty, therefore bool("False") returns True. This is distinct from the Boolean literal False.
Section 11: Comprehensive Understanding
41. Which statement accurately describes the print() and input() functions? A) print() sends output to a file, input() receives data from a file. B) print() displays data to the standard output, input() reads data from the standard input. C) print() is a compiler directive, input() is an interpreter directive. D) Both functions modify the source code of a program. Answer: B Explanation: print() is an output function that writes data (converted to strings) to the console (standard output). input() is an input function that pauses execution to read a line of text entered by the user from the console (standard input). 42. Given the code values = [True, False, 0, 1, "", "A"], how many items in this list are considered "falsy" in a Boolean context? A) 1 B) 2 C) 3 D) 4 Answer: C Explanation: In Python Boolean contexts, False, 0 (numeric zero), 0.0, empty sequences ("", [], ()), and empty collections are falsy. From the list: False, 0 , and "" (empty string) are falsy. True, 1 , and "A" (non-empty string) are truthy. 43. What is the key difference between = and == in Python? A) = is used for comparison, == is used for assignment. B) = is used for assignment, == is used for comparison (equality). C) Both are used for assignment, but == is for floating-point numbers. D) There is no difference; they are interchangeable. Answer: B Explanation: The single equals sign (=) is the assignment operator , used to bind a value to a
creation (though if it contains mutable objects like lists, those inner objects can change). This makes tuples suitable for fixed data.
47. What does the \ character at the end of a physical line of Python code signify? A) A syntax error. B) A line continuation, allowing a logical line to span multiple physical lines. C) The start of a comment. D) A division operation. Answer: B Explanation: A backslash () at the end of a line is an explicit line continuation character. It tells the Python interpreter that the current logical line of code continues onto the next physical line, preventing a syntax error. 48. The statement a = b = c = 0 is valid in Python. What does it do? A) It compares three variables for equality. B) It assigns the value 0 to all three variables a, b, and c. C) It creates a tuple (a, b, c) with the value 0. D) It checks if a, b, and c are all equal to zero. Answer: B Explanation: This is an example of chained assignment. The expression c = 0 is evaluated (assigning 0 to c), and its result (the value 0 ) is then assigned successively to b and a. All three variables end up referencing the same integer object 0. 49. Which operator has the highest precedence in the expression - 2 ** 2 + 3 * 4? A) - (unary negation) B) ** (exponentiation) C) * (multiplication) D) + (addition) Answer: B Explanation: Exponentiation (**) has the highest precedence among these operators.
Therefore, 2 ** 2 is evaluated first, yielding 4. Note that the unary - is applied after the exponentiation, so - 2 ** 2 is - 4 , not 4.
50. What is a key advantage of using an interpreted language like Python during development? A) Execution speed is typically faster than compiled languages. B) The resulting executable file is smaller. C) It allows for rapid testing and debugging with immediate feedback. D) It does not require any form of translation to run. Answer: C Explanation: A major advantage of interpreted languages is the development cycle speed. Programmers can run code immediately without a separate compilation step, receiving instant feedback from the interpreter on errors or output, which facilitates debugging and iterative testing. Section 12: Critical Analysis and Best Practices 51. Why is it important for a Python programmer to understand the concept of "truthiness"? A) It is only relevant for the if and while keywords. B) It allows any object to be used in a Boolean context, making code more concise and Pythonic. C) It is a deprecated feature and should be avoided. D) It determines the memory size of an object. Answer: B Explanation: Truthiness —the inherent Boolean value of any object—is central to Python's design. It allows conditional statements (if, while) and operators like and/or to work with any type, enabling concise expressions like if my_list: instead of if len(my_list) > 0:. 52. When comparing the list and tuple data types, which factor is most critical for choosing a tuple? A) When you need to frequently append or remove items. B) When you need to ensure data integrity and prevent accidental modification. C) When you require constant-time membership testing. D) When you need to associate keys with values.