1Which of the following describes the correct order of the Python execution model? A) Source code -> PVM -> Bytecode, B) Bytecode -> Source code -> PVM, C) Source code -> Bytecode -> PVM, D) PVM -> Bytecode -> Source code
C) Source code -> Bytecode -> PVM. Explanation: Python first takes the human-readable Source code and compiles it into an intermediate, platform-independent Bytecode. Finally, the Python Virtual Machine (PVM) interprets that bytecode into machine-specific instructions to execute the program.
2Which operator should you use to check if two variables point to the same memory location (identity), and what will print(a is b) return if a = [1, 2] and b = [1, 2]? A) ==, True B) is, True C) is, False D) id(), True
Correct Answer: C) is, False. Explanation: In Python, the == operator checks for equality (value), while the is operator checks for identity (memory location). Even though the lists contain the same integers, they are distinct objects in memory. You can verify this in PyCharm by checking id(a) and id(b)
3What is the result of the expression 2 ** 3 ** 2? A) 64 B) 512 C) 81 D) 12
Correct Answer: B) 512. Explanation: The exponentiation operator ** is right-associative in Python. This means it is evaluated from right to left: 3 ** 2 is 9, and then 2 ** 9 is 512.
4Which of the following represents a bitwise Shift Right operation on the integer 8 (binary 1000) by two positions? A) 8 << 2 B) 8 >> 2 C) 8 ** 2 D) 8 // 2
Correct Answer: B) 8 >> 2. Explanation: The >> operator shifts bits to the right. Shifting 1000 (8) right by two places results in 0010 (2). This is often used in low-level data engineering for efficient division by powers of two.
5What is the output of print(0O11 + 0X11)? A) 22 B) 26 C) 32 D) 28
Correct Answer: B) 26. Explanation: Python handles different numeric literals. 0O11 is Octal (Base 8), which equals 9 in decimal (\1 \times 8 + 1). `0X11` is Hexadecimal (Base 16), which equals 17 in decimal (\1 \times 16 + 1). \9 + 17 = 26.
6Which of the following is an invalid identifier in Python? A) _my_var B) 2_data_points C) processing_v1 D) SQL_Join_Result
Correct Answer: B) 2_data_points. Explanation: Python identifiers (variable names) cannot start with a digit. They must start with a letter or an underscore. This is a fundamental rule tested in the PCEP exam.
7What will be the output of print(None == False)? A) True B) False C) TypeError D) None
Correct Answer: B) False. Explanation: None represents the absence of a value (similar to SQL NULL), but it is a distinct singleton object of the NoneType. It is not numerically equivalent to False (which is 0).
8Which exception is raised when you try to divide a number by zero? A) ArithmeticError B) ValueError C) ZeroDivisionError D) DivisionError
Correct Answer: C) ZeroDivisionError. Explanation: While ZeroDivisionError is a subclass of ArithmeticError, Python raises the most specific exception possible. Understanding the Exception Hierarchy is a key PCEP requirement.
9What is the result of the bitwise AND operation 5 & 3? A) 8 B) 1 C) 7 D) 2
Correct Answer: B) 1. Explanation: In binary, 5 is 101 and 3 is 011. Performing a bitwise AND (&) results in 001, which is 1 in decimal.
10Which function is used to get the unique integer identifier of an object, representing its address in memory? A) hex() B) address() C) id() D) loc()
Correct Answer: C) id(). Explanation: The id() function returns the "identity" of an object, which is guaranteed to be unique and constant for this object during its lifetime in the Python PVM.
11What is the output of print("Python"[-1])? A) P B) n C) o D) IndexError
Correct Answer: B) n. Explanation: Python supports negative indexing. [-1] refers to the last character of a string or element of a list. For "Python", the last character is 'n'.
12What is the output of print(1 // 2 * 3)? A) 0 B) 1.5 C) 0.5 D) 1
Correct Answer: A) 0. Explanation: In Python, expressions are evaluated left-to-right. 1 // 2 is integer division, which results in 0. Then, 0 * 3 results in 0. This highlights the importance of operator precedence and integer division in the PCEP syllabus.
13Which of the following is an immutable data type in Python? A) List B) Dictionary C) Tuple D) Set
Correct Answer: C) Tuple. Explanation: Tuples are immutable, meaning their elements cannot be changed after creation. In the context of BI, think of a Tuple as a fixed record or a "read-only" row, whereas a List is like a staging table you can still modify.
14What will be the output of bool('')? A) True B) False C) None D) Error
Correct Answer: B) False. Explanation: In Python, empty sequences (like an empty string '', list [], or tuple ()) are Truthy evaluated as False. This is crucial for writing efficient conditional logic when checking for missing data in your pipelines.
15Which keyword is used to start an alternative branch if the if condition is False, but includes a new specific condition? A) else B) else if C) elseif D) elif
Correct Answer: D) elif. Explanation: Python uses elif (short for else if). This is the standard way to chain multiple logical tests. As a Senior BI Dev, you can relate this to a SQL CASE statement's WHEN clauses.
16What is the result of print(len({1, 2, 2, 3}))? A) 4 B) 3 C) 2 D) TypeError
Correct Answer: B) 3. Explanation: The curly braces {} here define a Set. Sets automatically deduplicate elements. Therefore, the set contains {1, 2, 3}, and its length is 3. This is similar to a SELECT DISTINCT operation in SQL.
17How do you write the number 13 in binary literal format in Python? A) 0b1101 B) 0x1101 C) b'1101' D) 0o1101
Correct Answer: A) 0b1101. Explanation: Binary literals in Python must start with the 0b prefix. 0x is for Hexadecimal and 0o is for Octal. Understanding these literals is a core requirement for the "Data Types and Literals" section of the PCEP.
18What is the output of print(1 + 2 * 3 ** 2)? A) 27 B) 19 C) 37 D) 81
Correct Answer: B) 19. Explanation: Following PEMDAS/BODMAS, exponentiation (**) comes first: 3 ** 2 = 9. Next is multiplication: 2 * 9 = 18. Finally, addition: 1 + 18 = 19.
19Which of these is the correct way to handle a specific exception in a try block? A) catch ValueError: B) except ValueError: C) trap ValueError: D) error ValueError
:Correct Answer: B) except ValueError:. Explanation: Python uses the try...except block for exception handling. The PCEP exam tests your knowledge of these keywords and how the Python interpreter routes errors.
20What will type(3.14) return? A) <class 'int'> B) <class 'float'> C) <class 'decimal'> D) <class 'str'>
Correct Answer: B) <class 'float'>. Explanation: In Python, any number with a decimal point is automatically treated as a float. You can verify this in the PyCharm console using the type() build-in function.
21What is the output of print("Data" + 2)? A) Data2 B) DataData C) TypeError D) Data 2
Correct Answer: C) TypeError. Explanation: Unlike some languages that perform "implicit type casting," Python is strongly typed. You cannot concatenate a string and an integer directly. You would need to use str(2) or an f-string like f"Data{2}".
22What is the output of print(10 % 3)? A) 1 B) 3 C) 3.33 D) 0
Correct Answer: A) 1. Explanation: The modulo operator % returns the remainder of a division. Since 3 goes into 10 three times with 1 left over, the result is 1.
23Which of these is the correct syntax for a multi-line comment in Python? A) // comment B) comment */ C) """ comment """ D) # comment #
Correct Answer: C) """ comment """. Explanation: While # is used for single-line comments, triple quotes (docstrings) are the standard way to create multi-line comments or documentation in Python scripts.
24What is the result of print(3 * 'Abacus')? A) AbacusAbacusAbacus B) Error C) 3Abacus D) 'Abacus, Abacus, Abacus'
Correct Answer: A) AbacusAbacusAbacus. Explanation: In Python, the * operator used with a string and an integer performs string replication. This is a handy shortcut for creating visual separators in console logs.
25What will print(1 == 1.0) return? A) True B) False C) TypeError D) None
Correct Answer: A) True. Explanation: Even though one is an integer and the other is a float, Python's == operator compares the mathematical value. Since 1 is numerically equal to 1.0, it returns True.
26Which function is used to convert a string like "123" into an integer? A) str() B) parse() C) int() D) chr()
Correct Answer: C) int(). Explanation: The int() constructor converts compatible types into integers. This is essential in Data Engineering when cleaning CSV data where numbers often arrive as strings.
27What is the escape character used to insert a newline in a string? A) \t B) \n C) D) \
Correct Answer: B) \n. Explanation: \n is the standard escape sequence for a newline. \t is for a tab. Using these correctly ensures your data pipeline reports are formatted properly.
28What is the default value of the end parameter in the print() function? A) ' ' B) '\t' C) '\n' D) ''
Correct Answer: C) '\n'. Explanation: By default, every print() statement ends with a newline. You can override this (e.g., print(x, end=' ')) to keep output on the same line.
29What is the output of print(float("1.5") * 2)? A) 3 B) 3.0 C) "1.51.5" D) Error
Correct Answer: B) 3.0. Explanation: The string is converted to the float 1.5. Multiplying a float by an integer always results in a float, so the output is 3.0.
30Which logical operator has the highest precedence? A) or B) and C) not D) all share equal precedence
Correct Answer: C) not. Explanation: In Python's logical operator hierarchy, not is evaluated first, followed by and, and finally or.
31What will be the result of list('BI')? A) ['BI'] B) ['B', 'I'] C) ('B', 'I') D) Error
Correct Answer: B) ['B', 'I']. Explanation: When you pass a string to the list() constructor, it iterates over the string and creates a list of its individual characters.
32What happens if you try to access a list index that does not exist? A) Returns None B) Returns 0 C) Raises IndexError D) Raises ValueError
Correct Answer: C) Raises IndexError. Explanation: Python strictly enforces bounds. Accessing an index outside the range of a list or tuple will immediately raise an IndexError.
33What is the result of 2 + 3 * 4? A) 20 B) 14 C) 24 D) 9
Correct Answer: B) 14. Explanation: Multiplication has higher precedence than addition. So, 3 * 4 = 12, and 2 + 12 = 14.
34How do you define a function in Python? A) function my_func(): B) def my_func(): C) void my_func(): D) define my_func()
:Correct Answer: B) def my_func():. Explanation: The def keyword is used to define functions. Remember to use snake_case for function names to follow PEP 8 standards.
35What is the output of print(bool(0), bool(0.0), bool(None))? A) True True True B) False False False C) False False True D) Error
Correct Answer: B) False False False. Explanation: In a boolean context, 0, 0.0, and None are all considered Falsy values in Python.
36Which of the following is used to remove and return the last item from a list? A) delete() B) pop() C) remove() D) discard()
Correct Answer: B) pop(). Explanation: The .pop() method removes the element at the given index (defaulting to the last one) and returns it. This is useful for processing stacks of data.
37What is the significance of the _ (underscore) variable in an interactive Python session? A) Private variable B) It stores the result of the last expression C) It deletes an object D) It is a syntax error
Correct Answer: B) It stores the result of the last expression. Explanation: In the Python REPL (or PyCharm's Python Console), _ automatically holds the result of the most recent calculation.
38Which method is used to add an element to the end of a list? A) add() B) push() C) append() D) insert()
Correct Answer: C) append(). Explanation: .append() is the standard method for adding a single element to the end of an existing list.
39What is the result of not (5 > 3)? A) True B) False C) 5 D) 3
Correct Answer: B) False. Explanation: 5 > 3 is True. Applying the not operator flips it to False.
40What will print("a" > "b") return? A) True B) False C) TypeError D) 0
Correct Answer: B) False. Explanation: String comparisons in Python are based on ASCII/Unicode values. Since 'a' (97) comes before 'b' (98), 'a' is not greater than 'b'.
41In a try...except block, which block is executed only if NO exceptions were raised? A) finally B) else C) catch D) except
Correct Answer: B) else. Explanation: The else block follows all except blocks and runs only if the code in the try block completes without an error. Use it for code that should only run on success.
42What is the output of print(bin(10))? A) 1010 B) 0b1010 C) 0x1010 D) 10
Correct Answer: B) 0b1010. Explanation: The bin() function converts an integer to its binary string representation, which always includes the 0b prefix.
43Which of the following is the bitwise XOR operator in Python? A) ^ B) & C) | D) ~
Correct Answer: A) ^. Explanation: The caret ^ is used for bitwise XOR (exclusive OR), where the resulting bit is 1 if the input bits are different.
44What will print(10 / 2) return? A) 5 B) 5.0 C) 2 D) 5.1
Correct Answer: B) 5.0. Explanation: In Python 3, the / operator always performs float division, even if the numbers divide evenly.
45Which keyword is used to skip the rest of the current loop iteration and move to the next one? A) break B) pass C) continue D) skip
Correct Answer: C) continue. Explanation: continue stops the current loop cycle and jumps immediately to the start of the next iteration.
46What is the result of len("Python\n")? A) 6 B) 7 C) 8 D) 5
Correct Answer: B) 7. Explanation: Escape sequences like \n represent a single character (the newline character). "Python" (6) + "\n" (1) = 7.
47What will be the output of print(round(2.5)), print(round(3.5))? A) 2, 3 B) 3, 4 C) 2, 4 D) 3, 3
Correct Answer: C) 2, 4. Explanation: Python uses "Banker's Rounding" (rounding to the nearest even number) for .5 cases to reduce bias in statistical data.
48Which method is used to turn all characters in a string to uppercase? A) upper() B) to_upper() C) uppercase() D) capitalize()
Correct Answer: A) upper(). Explanation: The .upper() string method creates a new string with all alphabetic characters converted to uppercase.
49What is the output of print(type(1 / 1))? A) <class 'int'> B) <class 'float'> C) <class 'number'> D) <class 'decimal'>
Correct Answer: B) <class 'float'>. Explanation: Division with / always produces a float result, regardless of the inputs.
50Which operator is used to check if a value exists within a sequence (like a list or string)? A) exists B) in C) has D) find
Correct Answer: B) in. Explanation: The in operator is a membership operator that returns True if the element is found in the sequence.
51What is the result of bool([0])? A) True B) False C) 0 D) Error
Correct Answer: A) True. Explanation: An empty list [] is Falsy, but a list containing any element (even 0) is Truthy.
52How do you create an empty dictionary? A) dict = [] B) dict = () C) dict = {} D) dict = set()
Correct Answer: C) dict = {}. Explanation: Curly braces define a dictionary. Note that set() must be used for an empty set because {} is reserved for dictionaries.
53What is the bitwise NOT of 0? A) 0 B) 1 C) -1 D) NULL
Correct Answer: C) -1. Explanation: Bitwise NOT (~) calculates -(x + 1). So ~0 becomes -(0 + 1), which is -1.
54What is the output of print('apple' < 'banana')? A) True B) False C) TypeError D) 1
Correct Answer: A) True. Explanation: Python compares strings lexicographically (dictionary order). Since 'a' comes before 'b' in Unicode, the expression is True.
55Which function allows you to get user input as a string? A) get() B) scan() C) input() D) read()
Correct Answer: C) input(). Explanation: The input() function pauses execution to read a line from the user and always returns it as a string.
56What is the result of min(5, 10, -2, 4)? A) 5 B) 10 C) -2 D) 4
Correct Answer: C) -2. Explanation: The min() function returns the smallest value among the arguments provided.
57Which keyword is used to create a loop that runs as long as a condition remains True? A) for B) until C) while D) during
Correct Answer: C) while. Explanation: A while loop checks a condition before every iteration and continues as long as that condition evaluates to True.
58What will print("a" * 0) output? A) a B) 0 C) "" (empty string) D) Error
Correct Answer: C) "" (empty string). Explanation: Multiplying a string by 0 or a negative integer results in an empty string.
59What is the result of 2 ** 0? A) 0 B) 2 C) 1 D) Error
Correct Answer: C) 1. Explanation: In Python (and mathematics), any number raised to the power of 0 is 1.
60Which built-in function returns the number of items in an object? A) count() B) size() C) len() D) length()
Correct Answer: C) len(). Explanation: len() is used to get the length of strings, lists, tuples, dictionaries, and sets.
61What is the output of print(1_000 + 1)? A) Error B) 10001 C) 1001 D) 1_001
Correct Answer: C) 1001. Explanation: Python allows underscores in numeric literals as visual separators for readability; the interpreter ignores them during execution.
62What is the result of print(0.1 + 0.2 == 0.3)? A) True B) False C) TypeError D) MachineError
Correct Answer: B) False. Explanation: Due to how floating-point numbers are represented in binary (IEEE 754), 0.1 + 0.2 actually results in 0.30000000000000004. For PCEP, remember that floats can have precision issues compared to integers.
63Which statement is used to exit a loop prematurely, skipping the else block of the loop if provided? A) exit B) stop C) break D) return
Correct Answer: C) break. Explanation: The break statement terminates the current loop immediately. If a loop has an else clause, it is skipped if the loop was exited via break.
64What is the result of the expression 15 // 4? A) 3.75 B) 4 C) 3 D) 0
Correct Answer: C) 3. Explanation: The // operator performs floor division, which divides the numbers and rounds down to the nearest integer.
65Which of the following creates a range of numbers from 0 up to, but not including, 5? A) range(5) B) range(1, 5) C) range(0, 6) D) list(5)
Correct Answer: A) range(5). Explanation: range(stop) generates integers starting at 0 and ends at stop - 1. This is identical to how LIMIT or indexing works in many BI tools.
66What will be the output of print(1 == True)? A) True B) False C) TypeError D) None
Correct Answer: A) True. Explanation: In Python, bool is a subclass of int. True is numerically equivalent to 1, and False is equivalent to 0.
67What is the value of x after x = 5; x += 3 * 2? A) 16 B) 11 C) 13 D) 10
Correct Answer: B) 11. Explanation: Augmented assignment operators (+=) have lower precedence than arithmetic operators. First 3 * 2 is calculated (6), then it is added to x (5 + 6 = 11).
68Which function converts an integer to its hexadecimal string representation? A) bin() B) oct() C) hex() D) dec()
Correct Answer: C) hex(). Explanation: The hex() function converts a number to a lowercase hexadecimal string prefixed with 0x.
69What is the result of 'hello'.capitalize()? A) HELLO B) Hello C) hello D) hELLO
Correct Answer: B) Hello. Explanation: The .capitalize() method returns a copy of the string with only its first character capitalized and the rest lowercased.
70Which of these is a correct way to create a list with three zeros? A) [0] * 3 B) list(0,0,0) C) {0,0,0} D) 3 * [0,0,0]
Correct Answer: A) [0] * 3. Explanation: Using the replication operator * on a list [0] creates a new list containing that element repeated three times.
71What is the output of print(True or False and False)? A) True B) False C) None D) Error
Correct Answer: A) True. Explanation: The and operator has higher precedence than or. False and False is evaluated first (False), then True or False is evaluated (True).
72Which method adds all elements of an iterable (like another list) to the end of a list? A) append() B) add() C) extend() D) plus()
Correct Answer: C) extend(). Explanation: While .append() adds a single item, .extend() takes an iterable and adds each of its elements individually to the end.
73What will be the result of print(type(()))? A) <class 'list'> B) <class 'tuple'> C) <class 'set'> D) <class 'dict'>
Correct Answer: B) <class 'tuple'>. Explanation: Empty parentheses () represent an empty tuple. Note that a single-element tuple requires a comma, e.g., (1,).
74What is the output of print(abs(-5.8))? A) -5.8 B) 5 C) 5.8 D) -5
Correct Answer: C) 5.8. Explanation: The abs() function returns the absolute value of a number (its distance from zero), making any negative number positive.
75Which keyword is used to pass over a block of code without doing anything? A) skip B) void C) pass D) continue
Correct Answer: C) pass. Explanation: pass is a null operation. It is used as a placeholder when a statement is syntactically required but you don't want any code to execute.
76What is the result of 2 + 3 == 5 and 4 + 4 == 7? A) True B) False C) 5 D) 8
Correct Answer: B) False. Explanation: Python evaluates the comparisons first. 5 == 5 is True, but 8 == 7 is False. True and False results in False.
77What will print("A" * 2 + "B" * 2) output? A) ABAB B) AABB C) AB D) Error
Correct Answer: B) AABB. Explanation: Replication * happens before concatenation +. So "AA" and "BB" are created first, then combined to form "AABB".
78Which of these is a "ValueError"? A) 1 / 0 B) int("abc") C) "a" + 1 D) print(x) where x is undefined
Correct Answer: B) int("abc"). Explanation: ValueError occurs when a function receives an argument of the correct type but an inappropriate value (like a string that isn't a valid number).
79How do you check the version of Python via code? A) python --version B) import sys; print(sys.version) C) sys.get_version() D) os.version()
Correct Answer: B) import sys; print(sys.version). Explanation: The sys module in the Standard Library provides access to variables used or maintained by the interpreter, including the version string.
80What is the output of print(bool("False"))? A) True B) False C) None D) Error
Correct Answer: A) True. Explanation: Any non-empty string is True. Even though the text says "False", the string itself is not empty, so it evaluates to True.
81What is the correct syntax for an f-string in Python? A) f"Value is {val}" B) "Value is {val}".f() C) f(Value is {val}) D) string(f, "Value is {val}")
Correct Answer: A) f"Value is {val}". Explanation: Formatted string literals (f-strings) start with f or F and use curly braces to evaluate expressions directly within the string.
82What is the result of the expression 1 // 2? A) 0.5 B) 0 C) 1 D) 0.0
Correct Answer: B) 0. Explanation: The // operator is floor division. It divides the numbers and rounds the result down to the nearest integer. 1 / 2 is 0.5, which floors to 0
83Which of the following is the correct way to start a for loop that iterates from 1 to 10? A) for i in range(1, 10): B) for i in range(1, 11): C) for i from 1 to 10: D) for (i=1; i<=10; i++)
:Correct Answer: B) for i in range(1, 11):. Explanation: The range(start, stop) function is inclusive of the start but exclusive of the stop. To include 10, the stop value must be 11.
84What is the output of print(bin(0XF))? A) 0b1111 B) 0b15 C) 1111 D) 0b1010
Correct Answer: A) 0b1111. Explanation: 0XF is hexadecimal for 15. The bin() function converts 15 to its binary representation, which is 1111, prefixed with 0b.
85Which exception is raised when a local or global name is not found? A) AttributeError B) ValueError C) NameError D) LookupError
Correct Answer: C) NameError. Explanation: NameError occurs when you try to access a variable or function name that has not been defined in the current scope.
86What is the result of len(["Data", [1, 2, 3]])? A) 4 B) 2 C) 5 D) TypeError
Correct Answer: B) 2. Explanation: The list contains two elements: the string "Data" and another list [1, 2, 3]. Nesting does not increase the top-level count.
87What does the isnot operator do in Python? A) Checks if values are unequal B) It is not a valid operator C) Checks if objects have different identities D) Inverts a boolean
Correct Answer: B) It is not a valid operator. Explanation: While is not (two words) is a valid operator, isnot (one word) will result in a SyntaxError. Python keywords and operators are space-sensitive.
88What is the result of 16 >> 1? A) 32 B) 15 C) 8 D) 4
Correct Answer: C) 8. Explanation: The >> operator is a bitwise right shift. Shifting a number right by 1 bit is mathematically equivalent to floor division by 2.
89Which method is used to remove all items from a list? A) delete() B) clear() C) remove_all() D) reset()
Correct Answer: B) clear(). Explanation: The .clear() method removes every element from a list, leaving it as an empty list [].
90What is the output of print(pow(2, 3, 2))? A) 8 B) 0 C) 1 D) 4
Correct Answer: B) 0. The output is 0 because `pow(2, 3, 2)` is Modular Exponential, it’s calculates 2 raised to the power of 3, which is 8, and then finds the remainder when that result is divided by 2. Since 8 is exactly divisible by 2, there is no remainder, resulting in 0. Modular exponentiation means raising a number to a power and then finding the remainder after division by another number.
91Correct Answer: B) 3.
This is determined by the order of operations (operator precedence). In Python, the modulo operator `%` and the multiplication operator `*` have the same level of precedence, so the expression is evaluated from left to right:
1. First, it calculates `7 % 2`, which equals `1` (because 7 divided by 2 leaves a remainder of 1).
2. Then, it takes that result and multiplies it by 3: `1 * 3`, which equals `3`.
What is the result of 7 % 2 * 3? A) 1 B) 3 C) 0 D) 6
92What is the output of print(ord('A'))? A) 65 B) 97 C) 1 D) 'A'
Correct Answer: A) 65. Explanation: The ord() function returns the Unicode code point of a single character. 'A' is 65, while 'a' is 97.
93Which of the following creates a single-element tuple? A) (1) B) tuple(1) C) (1,) D) [1]
Correct Answer: C) (1,). Explanation: Without the trailing comma, Python treats (1) as an integer inside parentheses. The comma is what actually defines the tuple.
94What is the result of round(2.501)? A) 2 B) 3 C) 2.5 D) 2.0
Correct Answer: B) 3. Explanation: While 2.5 rounds to 2 (Banker's rounding), 2.501 is strictly closer to 3 than 2, so it rounds up.
95What will be the output of print("abc" < "ABC")? A) True B) False C) TypeError D) None
Correct Answer: B) False. Explanation: In Unicode, uppercase letters have lower numeric values (A=65) than lowercase letters (a=97). Thus, "abc" is "greater than" "ABC".
96Which keyword is used to return a value from a function? A) give B) result C) return D) back
Correct Answer: C) return. Explanation: The return keyword exits a function and sends a specific value back to the caller.
97What is the output of print(type(id(5)))? A) <class 'id'> B) <class 'hex'> C) <class 'int'> D) <class 'address'>
Correct Answer: C) <class 'int'>. Explanation: The id() function always returns an integer representing the memory address.
98What is the result of ~(-1)? A) 1 B) 0 C) -1 D) -2
Correct Answer: B) 0. Explanation: The bitwise NOT operator ~x is calculated as -(x + 1). So, -(-1 + 1) equals 0.
99Which of the following is a Python keyword and cannot be used as a variable name? A) integer B) string C) while D) total
Correct Answer: C) while. Explanation: while is a reserved keyword in Python used for control flow. integer and string are not keywords (though int and str are built-in types).
100What is the result of 10 / 4? A) 2 B) 2.5 C) 2.0 D) 3
Correct Answer: B) 2.5. Explanation: In Python 3, the / operator always performs floating-point division, returning the exact decimal result.
101What is the output of print(int(1.9))? A) 2 B) 1 C) 1.0 D) Error
Correct Answer: B) 1. Explanation: Converting a float to an int using int() does not round; it truncates the decimal portion toward zero.
102Which collection type does NOT allow duplicate elements? A) List B) Tuple C) Set D) Dictionary Values
Correct Answer: C) Set. Explanation: Sets are unordered collections of unique elements. If you add a duplicate to a set, it is simply ignored.
103What is the name of the function that outputs the character associated with a specific Unicode code point (e.g., converting 65 back to 'A')? A) ord() B) chr() C) str() D) unicode()
Correct Answer: B) chr(). Explanation: While ord() gets the number from a character, chr() (character) does the opposite. In your pipelines, this is how you might handle special symbols or control characters.
104Which keyword is used to import a specific function from a module so you can use it without the module prefix? A) include B) from C) using D) with
Correct Answer: B) from. Explanation: Using from math import sqrt allows you to call sqrt(16) directly instead of math.sqrt(16). PCEP tests your understanding of the different ways to structure imports.
105What is the result of bool(0.00000000001)? A) True B) False C) 0 D) None
Correct Answer: A) True. Explanation: Any non-zero numeric value, no matter how small, is considered True in a boolean context. Only exactly 0 or 0.0 (and None/empty sets) are False.
106Which statement about Python's else clause in a while loop is TRUE? A) It never executes B) It executes only if the loop is terminated by a break C) It executes once when the loop condition becomes False D) It is not valid syntax in Python
Correct Answer: C) It executes once when the loop condition becomes False. Explanation: This is a unique Python feature. The else block runs after the loop finishes normally. If the loop is "broken" by a break statement, the else is skipped.
107What will be the output of print("Python"[1:4])? A) Pyt B) yth C) ytho D) thon
Correct Answer: B) yth. Explanation: Slicing [start:stop] starts at index 1 ('y') and goes up to, but does not include, index 4 ('o'). So it captures indices 1, 2, and 3.
108Which of the following is the correct way to check if 'a' is NOT in a list called my_list? A) a not in my_list B) not(a in my_list) C) a != in my_list D) Both A and B are correct
Correct Answer: D) Both A and B are correct. Explanation: a not in my_list is the more "Pythonic" and readable way (PEP 8), but not(a in my_list) is logically equivalent. PCEP often tests these variations.
109Which function tells you how many bytes an object occupies in memory? A) id() B) sys.getsizeof() C) len() D) size()
Correct Answer: B) sys.getsizeof(). Explanation: While len() counts items, sys.getsizeof() (from the sys module) returns the actual memory footprint. This is the "id() check" level of detail required for PCEP mastery.
110What is the result of 2 * 3 ** 2 // 2? A) 18 B) 9 C) 6.0 D) 4.5
Correct Answer: B) 9. Explanation: Order of execution: Exponentiation first (3^2 = 9), then Multiplication (2 * 9 = 18), then Floor Division (18 // 2 = 9). Multiplication and Division share precedence, so they go left-to-right.
111What is the result of None is None? A) True B) False C) TypeError D) None
Correct Answer: A) True. Explanation: None is a singleton, meaning there is only one None object in memory. Therefore, any variable that is None will have the same identity as another None.
112Which operator is used for string concatenation? A) & B) + C) . D) ,
Correct Answer: B) +. Explanation: The + operator adds numbers or joins strings. Using it between two strings is the most basic way to combine text in a pipeline.
113What will be the output of print(id(5) == id(5.0))? A) True B) False C) TypeError D) Machine Dependent
Correct Answer: B) False. Explanation: An integer 5 and a float 5.0 are different objects of different classes created in the PVM. Their IDs (memory addresses) will be different.
114What is the result of int(False)? A) 0 B) 1 C) -1 D) Error
Correct Answer: A) 0. Explanation: Booleans are integers in Python. False has a numeric value of 0, and True has a numeric value of 1.
115Which keyword is used to provide a "fallback" block of code in a try statement that runs regardless of whether an exception occurred? A) always B) catch C) finally D) except
Correct Answer: C) finally. Explanation: The finally block is often used for "cleanup" tasks, like closing a database connection or a file, because it is guaranteed to run no matter what.
116What is the bitwise representation of the result of ~1? A) 0 B) -1 C) -2 D) 1
Correct Answer: C) -2. Explanation: The bitwise NOT ~x is calculated as -(x + 1). Therefore, ~1 becomes -(1 + 1), which is -2. This is a vital PCEP concept regarding how Python handles signed integers in memory.
117Which of the following is a valid keyword in Python and cannot be used as an identifier? A) sub B) switch C) in D) evaluate
Correct Answer: C) in. Explanation: in is a reserved keyword in Python used for membership testing. While switch is a keyword in other languages like C++ or Java, it is not a reserved keyword in Python (though match was recently added).
118What is the result of (1, 2) + (3, 4)? A) (1, 2, 3, 4) B) (4, 6) C) TypeError D) ((1, 2), (3, 4))
Correct Answer: A) (1, 2, 3, 4). Explanation: Similar to lists, tuples support the concatenation operator +, which joins them into a new, larger tuple.
119What is the output of print(1 == 1.0 and 1 is 1.0)? A) True True B) True False C) False False D) TypeError
Correct Answer: B) True False. Explanation: 1 == 1.0 is True because their values are equal. However, 1 is 1.0 is False because one is an int and the other is a float, meaning they are different objects in the PVM.
120Which list method removes an item based on its VALUE rather than its index? A) pop() B) delete() C) remove() D) discard()
Correct Answer: C) remove(). Explanation: .remove(value) searches for the first occurrence of the specified value and deletes it. To delete by index, you would use pop() or the del keyword.
121What is the result of 2 ** 3 ** 2 // 10? A) 6 B) 51 C) 0 D) 5
Correct Answer: B) 51. Explanation: Exponentiation is right-associative: \$3^2 = 9. Then \2^9 = 512. Finally, \512 // 10 is floor division, resulting in 51. Which of the following describes a "Syntax Error"? A) Dividing by zero B) Using a variable that isn't defined C) Forgetting the colon at the end of an `if` statement D) Passing the wrong type to a function
122Which exception is raised when an operation or function is applied to an object of inappropriate type? A) ValueError B) AttributeError C) TypeError D) LogicError
Correct Answer: C) TypeError. Explanation: TypeError occurs, for example, when you try to add a string to an integer: "A" + 1.
123What is the result of len("")? A) 0 B) 1 C) None D) Error
Correct Answer: A) 0. Explanation: An empty string contains no characters, so its length is 0.
124What will print(round(4.5)) output? A) 4 B) 5 C) 4.0 D) 5.0
Correct Answer: A) 4. Explanation: Following Banker's Rounding (nearest even integer), 4.5 rounds to 4, whereas 5.5 would round to 6. This is a common PCEP detail to memorize.
Python’s `round()` rounds a number to the closest integer: values ending below `.5` go down, while values above `.5` go up.
When the value ends exactly in `.5`, Python rounds to the nearest even integer—for example, `round(4.5)` is `4`, but `round(5.5)` is `6`.
125What is the result of 2 + 3 * 4? A) 20 B) 14 C) 9 D) 24
Correct Answer: B) 14. Explanation: Multiplication has higher precedence than addition, so 3 * 4 = 12, then 2 + 12 = 14.
126What is the result of (2 + 3) * 4? A) 20 B) 14 C) 9 D) 24
Correct Answer: A) 20. Explanation: Parentheses (the 'P' in PEMDAS) take highest precedence. 2 + 3 = 5, then 5 * 4 = 20.
127In Python, what is the associativity of the exponentiation operator (**)? A) Left-to-right B) Right-to-left C) Top-to-bottom D) None
Correct Answer: B) Right-to-left. Explanation: Exponentiation is right-associative, meaning 2 ** 3 ** 2 is evaluated as 2 ** (3 ** 2).
128What is the result of 10 - 2 + 3? A) 5 B) 11 C) 9 D) 15
Correct Answer: B) 11. Explanation: Addition and subtraction have equal precedence and are evaluated left-to-right. 10 - 2 = 8, then 8 + 3 = 11.
129What is the result of 10 / 2 * 5? A) 1 B) 25.0 C) 1.0 D) 10
Correct Answer: B) 25.0. Explanation: Multiplication and division have equal precedence and evaluate left-to-right. 10 / 2 = 5.0, then 5.0 * 5 = 25.0.
130What is the order of precedence between multiplication (*) and floor division (//)? A) Multiplication is higher B) Floor division is higher C) They have equal precedence D) Neither has precedence
Correct Answer: C) They have equal precedence. Explanation: Multiplication, division, floor division, and modulo all share the same precedence level and execute left-to-right.
131What is the result of 2 * 3 ** 2? A) 36 B) 18 C) 12 D) 54
Correct Answer: B) 18. Explanation: Exponentiation (**) comes before multiplication (*). 3 ** 2 = 9, then 2 * 9 = 18.
132What is the result of (2 * 3) ** 2? A) 36 B) 18 C) 12 D) 64
Correct Answer: A) 36. Explanation: Parentheses override default precedence. 2 * 3 = 6, and 6 ** 2 = 36.
133What is the result of 5 + 3 * 2 ** 2? A) 32 B) 17 C) 44 D) 11
Correct Answer: B) 17. Explanation: Exponentiation first (2 ** 2 = 4), then multiplication (3 * 4 = 12), then addition (5 + 12 = 17).
134What is the result of 10 // 3 * 3? A) 10 B) 9 C) 9.0 D) 1
Correct Answer: B) 9. Explanation: Floor division and multiplication evaluate left-to-right. 10 // 3 = 3, then 3 * 3 = 9.
135Which operators have the lowest precedence in Python's standard order of operations? A) Multiplication and Division B) Addition and Subtraction C) Exponentiation D) Comparison operators
Correct Answer: B) Addition and Subtraction. Explanation: Among arithmetic operators, addition and subtraction are evaluated last (lowest precedence).
136What is the result of 4 + 6 / 2 - 1? A) 4 B) 6.0 C) 5.0 D) 3.0
Correct Answer: B) 6.0. Explanation: Division happens first (6 / 2 = 3.0), then left-to-right addition and subtraction (4 + 3.0 - 1 = 6.0).
137What is the result of 2 ** 2 ** 3? A) 64 B) 256 C) 512 D) 4096
Correct Answer: B) 256. Explanation: Because ** is right-associative, it evaluates as 2 ** (2 ** 3). 2 ** 3 = 8, and 2 ** 8 = 256.
138What is the result of -3 ** 2 in Python? A) 9 B) -9 C) Error D) 6
Correct Answer: B) -9. Explanation: Exponentiation has higher precedence than the unary minus operator. It evaluates as -(3 ** 2), resulting in -9.
139What is the result of (-3) ** 2? A) 9 B) -9 C) Error D) 6
Correct Answer: A) 9. Explanation: Parentheses force the negative sign to be included in the exponentiation: (-3) * (-3) = 9.
140What is the result of 12 / 4 / 3? A) 1.0 B) 9.0 C) 0.0 D) 4.0
Correct Answer: A) 1.0. Explanation: Division is left-associative. 12 / 4 = 3.0, then 3.0 / 3 = 1.0.
141What is the result of 8 - 2 - 2? A) 8 B) 4 C) 0 D) 2
Correct Answer: B) 4. Explanation: Subtraction is left-to-right. 8 - 2 = 6, then 6 - 2 = 4.
142What is the result of 2 + 3 * (4 - 2)? A) 10 B) 8 C) 7 D) 12
Correct Answer: B) 8. Explanation: Parentheses first (4 - 2 = 2), then multiplication (3 * 2 = 6), then addition (2 + 6 = 8).
143What is the result of 10 % 3 * 2? A) 2 B) 1.5 C) 0 D) 6
Correct Answer: A) 2. Explanation: Modulo and multiplication have equal precedence and evaluate left-to-right. 10 % 3 = 1, then 1 * 2 = 2.
144What is the result of 2 * 3 // 4? A) 1 B) 1.5 C) 0 D) 2
Correct Answer: A) 1. Explanation: Multiplication and floor division evaluate left-to-right. 2 * 3 = 6, then 6 // 4 = 1.
145What prefix is used to designate a binary literal in Python? A) 0x B) 0b C) 0o D) 0d
Correct Answer: B) 0b. Explanation: The 0b or 0B prefix tells the Python interpreter that the following digits represent a binary (Base 2) number.
146What prefix is used to designate an octal literal in Python? A) 0t B) 0o C) 0x D) 0b
Correct Answer: B) 0o. Explanation: The 0o or 0O prefix indicates an octal (Base 8) integer literal.
147What prefix is used to designate a hexadecimal literal in Python? A) 0h B) 0x C) 0b D) 0o
Correct Answer: B) 0x. Explanation: The 0x or 0X prefix is used for hexadecimal (Base 16) literals.
148What is the decimal equivalent of the binary literal 0b1010? A) 5 B) 10 C) 12 D) 8
Correct Answer: B) 10. Explanation: Binary 1010 is calculated as (1×8)+(0×4)+(1×2)+(0×1)=10(1×8)+(0×4)+(1×2)+(0×1)=10.
149What is the decimal equivalent of the octal literal 0o12? A) 12 B) 10 C) 16 D) 8
Correct Answer: B) 10. Explanation: It should read (1×8^1)+(2×8^0)=8+2=10
150What is the decimal equivalent of the hexadecimal literal 0x10? A) 10 B) 16 C) 32 D) 256
Correct Answer: B) 16. Explanation: Hexadecimal 10 is calculated as (1×16^1)+(0×16^0)=16+0=16.
151Which built-in function converts an integer into a binary string? A) bin() B) oct() C) hex() D) str_bin()
Correct Answer: A) bin(). Explanation: The bin() function returns a string representation of an integer prefixed with 0b.
152Which built-in function converts an integer into an octal string? A) binary() B) oct() C) hex() D) base8()
Correct Answer: B) oct(). Explanation: The oct() function returns a string representation of an integer prefixed with 0o.
153Which built-in function converts an integer into a hexadecimal string? A) hex() B) hx() C) to_hex() D) base16()
Correct Answer: A) hex(). Explanation: The hex() function returns a string representation of an integer prefixed with 0x.
154What is the data type of the literal 0b1101 in Python? A) float B) str C) int D) bin
Correct Answer: C) int. Explanation: Regardless of the input base (binary, octal, hex), Python stores all integer literals as standard int objects in memory.
155Which digits are invalid when writing an octal literal like 0o...? A) 0 and 1 B) 7 and 8 C) 2 and 3 D) 4 and 5
Correct Answer: B) 7 and 8. Explanation: Octal is Base 8, meaning it only uses digits 0 through 7. Using 8 or 9 results in a SyntaxError.
156What letters are used in hexadecimal literals to represent values 10 through 15? A) A through F B) J through O C) P through U D) W through Z
Correct Answer: A) A through F. Explanation: Hexadecimal uses A (10), B (11), C (12), D (13), E (14), and F (15).
157What is the result of int("10", 2)? A) 10 B) 2 C) 16 D) 8
Correct Answer: B) 2. Explanation: The int(string, base) function parses the string "10" using Base 2 (binary), which equals decimal 2.
158What is the result of int("10", 8)? A) 10 B) 8 C) 16 D) 64
Correct Answer: B) 8. Explanation: Parsing the string "10" using Base 8 (octal) yields decimal 8.
159What is the result of int("10", 16)? A) 10 B) 16 C) 60 D) 100
Correct Answer: B) 16. Explanation: Parsing the string "10" using Base 16 (hexadecimal) yields decimal 16.
160What is the sum of 0b10 and 0o10 in decimal? A) 20 B) 10 C) 12 D) 18
Correct Answer: B) 10. Explanation: 0b10 is binary for 2, and 0o10 is octal for 8. \$2 + 8 = 10. What does `hex(15)` return? A) '0xf' B) '0XF' C) '15' D) '0b1111'
161Which method returns a view object of all values in a dictionary? A) get_values() B) values() C) items() D) content()
Correct Answer: B) values(). Explanation: The .values() method returns a view object containing all the values stored in the dictionary.
162What does my_dict.items() return? A) A list of keys B) A list of values C) A view object of (key, value) tuples D) A set of keys
Correct Answer: C) A view object of (key, value) tuples. Explanation: .items() displays a dynamic view of the dictionary's key-value pairs, which is useful in for loops.
163How do you safely check if a key exists in a dictionary before accessing it? A) using in operator B) using exists() method C) using has_key() method D) using search()
Correct Answer: A) using in operator. Explanation: The in operator checks dictionary keys efficiently (e.g., 'key' in my_dict). The older .has_key() method was removed in Python 3.
164What is the output of len({'a': 1, 'b': 2, 'c': 3})? A) 3 B) 6 C) 1 D) Error
Correct Answer: A) 3. Explanation: len() on a dictionary counts the number of key-value pairs.
165Which dictionary method removes all items from the dictionary? A) delete() B) clear() C) reset() D) remove()
Correct Answer: B) clear(). Explanation: The .clear() method empties the dictionary, leaving it with a length of 0.
166What is the result of bool({})? A) True B) False C) None D) Error
Correct Answer: B) False. Explanation: An empty dictionary evaluates to False in a boolean context.
167Can a dictionary value be another dictionary? A) No B) Yes C) Only if keys are integers D) Only in Python 3.13+
Correct Answer: B) Yes. Explanation: Dictionary values can be of any data type, including lists, tuples, or even nested dictionaries.
168What is the return type of my_dict.keys()? A) list B) tuple C) dict_keys view object D) set
Correct Answer: C) dict_keys view object. Explanation: It returns a dynamic view object that reflects changes to the dictionary in real-time.
169How do you update an existing dictionary with another dictionary's contents? A) d1.update(d2) B) d1 + d2 C) d1.merge(d2) D) d1.append(d2)
Correct Answer: A) d1.update(d2). Explanation: The .update() method merges key-value pairs from another dictionary or iterable into the target dictionary.
170What happens when you assign a value to a non-existent key in a dictionary? A) Raises a KeyError B) Adds the new key-value pair C) Raises an IndexError D) Ignored
Correct Answer: B) Adds the new key-value pair. Explanation: Dictionary assignment (e.g., d['new_key'] = 10) automatically creates the key if it doesn't already exist.
171Which built-in function can take a sequence of key-value pairs (like tuples) and build a dictionary? A) dict() B) create_dict() C) make_dict() D) bundle()
Correct Answer: A) dict(). Explanation: The dict() constructor accepts an iterable of key-value pairs to initialize a dictionary.
172What is the primary advantage of dictionaries over lists for lookups? A) Dictionaries are ordered B) Dictionaries use hash tables for O(1) average lookup time C) Dictionaries use less memory D) Dictionaries allow duplicate keys
Correct Answer: B) Dictionaries use hash tables for O(1) average lookup time. Explanation: Dictionaries are implemented using hash tables, making key-based lookups extremely fast compared to searching through a list.
173Question: What is the output of print("Python"[1:5:2])?
A) yh B) yt C) Pto D) ytn
Correct Answer: A) yh. Explanation: The slice [start:stop:step] begins at index 1 and stops before index 5, moving in steps of 2. Indexing "Python": P(0) y(1) t(2) h(3) o(4) n(5). Starting at index 1 ('y'), the next step lands on index 3 ('h'). Index 5 is excluded (stop boundary), so the result is 'yh'.
174Question: What does a negative step in string slicing (e.g., [::-1]) achieve? A) Reverses the string B) Deletes the string C) Raises an error D) Shifts characters left by one
Correct Answer: A) Reverses the string. Explanation: A step of -1 tells Python to traverse the sequence backward, from the last character to the first. Omitting start and stop ([::-1]) means "the whole sequence, reversed." This is the standard Pythonic idiom for reversing any sequence type (strings, lists, tuples).
175Question: What is the result of "DataEngineering"[::-1]? A) "gnireenignEataD" B) "DataEngineering" C) "gnireenigneEataD" D) Error
Correct Answer: A) "gnireenignEataD". Explanation: Applying [::-1] reverses the entire string character by character. Writing out "DataEngineering" (D-a-t-a-E-n-g-i-n-e-e-r-i-n-g) and reading it back-to-front gives "gnireenignEataD". Note capitalization is preserved per-character — the 'E' from the middle of the original string still appears as uppercase in the reversed output, just relocated.
176What string method checks if a string starts with a specific prefix? A) begins_with() B) startswith() C) find_prefix() D) check_start()
Correct Answer: B) startswith(). Explanation: The .startswith() method returns True if the string starts with the specified prefix.
177What does "Python".find("th") return? A) True B) 2 C) 3 D) -1
Correct Answer: B) 2. Explanation: .find() returns the lowest index where the substring is found. 't' starts at index 2 (P-y-t).
178What is the output of " hello ".strip()? A) " hello" B) "hello " C) "hello" D) " hello "
Correct Answer: C) "hello". Explanation: The .strip() method removes leading and trailing whitespace.
179How do you convert a string to all uppercase letters? A) .upper() B) .capitalize() C) .to_upper() D) .caps()
Correct Answer: A) .upper(). Explanation: The .upper() method returns a copy of the string with all cased characters converted to uppercase.
180What does "12345".isdigit() return? A) True B) False C) Error D) None
Correct Answer: A) True. Explanation: .isdigit() checks if all characters in the string are digits and the string is not empty.
181What is the result of "-".join(["a", "b", "c"])? A) "abc" B) "a-b-c" C) "-a-b-c" D) Error
Correct Answer: B) "a-b-c". Explanation: .join() concatenates elements of an iterable using the string as a separator.
182What does "Data, Engineer".split(",") return? A) "Data Engineer" B) ["Data", " Engineer"] C) ("Data", "Engineer") D) Error
Correct Answer: B) ["Data", " Engineer"]. Explanation: .split() breaks a string into a list of substrings based on the specified delimiter.
183What is the output of "Python".replace("P", "J")? A) "Jython" B) "Python" C) "Jython" D) "PythoJ"
Correct Answer: A) "Jython". Explanation: The .replace(old, new) method replaces occurrences of the substring.
184What does "hello".count("l") return? A) 1 B) 2 C) 3 D) 4
Correct Answer: B) 2. Explanation: .count() returns the number of non-overlapping occurrences of a substring.
185What is the result of "python".capitalize()? A) "PYTHON" B) "Python" C) "pYTHON" D) Error
Correct Answer: B) "Python". Explanation: .capitalize() converts the first character to uppercase and the rest to lowercase.
186What is the output of print("A" * 3)? A) "AAA" B) A3 C) Error D) 3A
Correct Answer: A) "AAA". Explanation: Multiplying a string by an integer repeats the string.
187How do you check if a substring exists within a string? A) using in operator B) using exists() C) using has() D) using search()
Correct Answer: A) using in operator. Explanation: The in operator performs a substring membership test in Python.
188What is the output of len("Data"[1:3])? A) 4 B) 2 C) 3 D) 1
Correct Answer: B) 2. Explanation: "Data"[1:3] extracts "at", which has a length of 2.
189What is the purpose of the else block attached to a for loop? A) It runs if an error occurs B) It runs only if the loop completes normally without hitting a break C) It runs every time the loop finishes D) It replaces the finally block
Correct Answer: B) It runs only if the loop completes normally without hitting a break. Explanation: The loop else clause is executed after the loop finishes its iterations, unless interrupted by a break statement.
190What happens if a break statement is executed inside a for loop that has an else clause? A) The else block runs normally B) The else block is skipped C) A SyntaxError is raised D) The program crashes
Correct Answer: B) The else block is skipped. Explanation: If the loop is terminated early via break, the associated else block does not execute.
191Which statement is used to skip the rest of the current iteration and jump to the next loop cycle? A) pass B) break C) continue D) skip
Correct Answer: C) continue. Explanation: continue terminates the current iteration prematurely and proceeds to the next loop evaluation.
192What is the output of this code snippet? for i in range(2): print(i, end="") else: print(3, end="") A) 013 B) 0123 C) 3 D) 01
Correct Answer: A) 013. Explanation: The loop prints 0 and 1, finishes normally without a break, and then executes the else block which prints 3.
193What is the output if a break is added? for i in range(2): if i == 1: break; print(i, end="") else: print(3, end="") A) 03 B) 0 C) 01 D) 3
Correct Answer: B) 0. Explanation: The loop prints 0, hits break when i == 1, exits immediately, and skips the else block entirely.
194Can a while loop have an else clause in Python? A) No B) Yes C) Only in Python 3 D) Only with a try block
Correct Answer: B) Yes. Explanation: Both for and while loops support an optional else clause that executes when the loop condition becomes false.
195What does the pass statement do inside a loop? A) Breaks the loop B) Skips an iteration C) Acts as a placeholder that does nothing D) Restarts the loop
Correct Answer: C) Acts as a placeholder that does nothing. Explanation: pass is a null statement used when syntax requires a statement but no action is needed.
196In a nested loop, what does a break statement affect? A) All loops in the program B) Only the innermost enclosing loop C) The outermost loop D) The entire function
Correct Answer: B) Only the innermost enclosing loop. Explanation: A break statement only exits the single, innermost loop in which it is placed.
197What is the output of x = 0; while x < 2: x += 1; else: print(x)? A) 0 B) 1 C) 2 D) Infinite loop
Correct Answer: C) 2. Explanation: The while loop increments x until it reaches 2. The loop terminates normally, executing the else block which prints 2.
198What happens if you use continue inside a while loop without updating the loop control variable? A) Nothing changes B) It may cause an infinite loop C) It raises a SyntaxError D) It exits the loop
Correct Answer: B) It may cause an infinite loop. Explanation: If continue skips past the variable increment step, the condition may remain permanently true, causing an infinite loop.
199Which keyword stops execution of a function entirely? A) break B) continue C) return D) pass
Correct Answer: C) return. Explanation: return exits the function immediately, whereas break only exits a loop.
200What is the result of using break outside of any loop or function? A) It works normally B) It raises a SyntaxError C) It acts like pass D) It exits the script silently
Correct Answer: B) It raises a SyntaxError. Explanation: break and continue can only appear syntactically nested within a for or while loop.
201How many times does the else block execute in a loop that runs 5 times and finishes? A) 0 times B) 1 time C) 5 times D) Infinite times
Correct Answer: B) 1 time. Explanation: The loop else block executes exactly once after all iterations complete without interruption.
202What is the output of for i in range(1): pass else: print("Done")? A) Done B) 0 C) 0Done D) Nothing
Correct Answer: A) Done. Explanation: The for loop passes on 0, completes normally, and triggers the else block to print "Done".
203Which loop structure is best when the number of iterations is known beforehand? A) while loop B) for loop C) try-except D) infinite loop
Correct Answer: B) for loop. Explanation: for loops are designed for iterating over sequences and known ranges.
204What is the default behavior of an infinite while True: loop when it encounters a break statement? A) It crashes B) It exits the loop and continues execution below it C) It restarts the script D) It raises a RuntimeError
Correct Answer: B) It exits the loop and continues execution below it. Explanation: A break is the standard way to terminate an otherwise infinite while True loop based on a runtime condition.
205What happens if you place code after a break statement inside the same loop block? A) It runs every time B) It is unreachable and ignored C) It causes a SyntaxError D) It runs before the break
Correct Answer: B) It is unreachable and ignored. Explanation: Any statements after a break in the same block are dead code because the break exits the loop immediately.
206Can you use else with a try-except block and a for loop simultaneously? A) No B) Yes, Python allows nested or sequential else clauses C) Only in functions D) It causes a SyntaxError
Correct Answer: B) Yes, Python allows nested or sequential else clauses. Explanation: A try-except-else block can contain a for loop with its own else clause without syntax conflict.
207What is the output of i = 0; while i < 3: i += 1; if i == 2: continue; print(i, end="")? A) 123 B) 13 C) 12 D) 23
Correct Answer: B) 13. Explanation: When i = 2, continue skips the print(), so only 1 and 3 are printed.
208What is the primary difference between break and return? A) break exits a loop; return exits a function B) break exits a function; return exits a loop C) They are identical D) return only works in while loops
Correct Answer: A) break exits a loop; return exits a function. Explanation: break stops loop iteration, while return exits the entire function scope and optionally passes back a value.
209What keyword is used in Python to define a user-defined function? A) func B) define C) def D) function
Correct Answer: C) def. Explanation: The def keyword introduces a function definition, followed by the function name and parentheses.
210What are the parameters defined in a function signature called during a function call? A) Arguments B) Variables C) Constants D) Objects
Correct Answer: A) Arguments. Explanation: When you call a function and pass values into it, those values are referred to as arguments.
211What is the scope of a variable assigned inside a function body? A) Global scope B) Local scope C) Built-in scope D) Module scope
Correct Answer: B) Local scope. Explanation: Variables created inside a function are local to that function and cannot be accessed directly outside of it.
212Which keyword allows a function to modify a variable defined in the global scope? A) global B) nonlocal C) shared D) mutable
Correct Answer: A) global. Explanation: The global keyword tells Python that a variable inside a function refers to the global namespace variable.
213What is a default argument in a Python function? A) An argument that must always be passed B) An argument with a pre-defined value if none is provided during the call C) An argument that only accepts integers D) An argument that cannot be changed
Correct Answer: B) An argument with a pre-defined value if none is provided during the call. Explanation: Default arguments (e.g., def greet(name="User"):) make parameters optional.
214What is the output of a function that contains no return statement? A) 0 B) False C) None D) Error
Correct Answer: C) None. Explanation: Functions without an explicit return statement implicitly return the None object.
215How do you pass arguments by explicitly naming them during a function call? A) Positional arguments B) Keyword arguments C) Default arguments D) Variable arguments
Correct Answer: B) Keyword arguments. Explanation: Keyword arguments use the parameter name (e.g., func(age=30, name="Alice")), allowing out-of-order passing.
216What syntax allows a function to accept an arbitrary number of positional arguments? A) *args B) **kwargs C) &args D) #args
Correct Answer: A) *args. Explanation: The * operator packs any number of extra positional arguments into a tuple named args.
217What syntax allows a function to accept an arbitrary number of keyword arguments? A) *args B) **kwargs C) &kwargs D) #kwargs
Correct Answer: B) **kwargs. Explanation: The ** operator packs extra keyword arguments into a dictionary.
218What is the result of assigning a mutable object (like a list) as a default parameter value? A) It creates a new list every time B) It shares the same list object across multiple calls C) It raises a SyntaxError D) It turns the list into a tuple
Correct Answer: B) It shares the same list object across multiple calls. Explanation: Default arguments are evaluated only once when the function is defined, which can cause unexpected state retention with mutable defaults.
219How do you import an entire module with a custom alias? A) import module as alias B) from module alias C) module alias D) load module as alias
Correct Answer: A) import module as alias. Explanation: The import X as Y syntax binds the module object to the local name Y.
220What is Python's inline conditional expression (ternary operator) syntax? A) x if condition else y B) condition ? x : y C) if condition: x else: y D) x when condition else y
Correct Answer: A) x if condition else y. Explanation: Python evaluates the middle condition and returns x if true, otherwise y.
221What is the output of print("Yes" if 5 > 2 else "No")? A) Yes B) No C) True D) False
Correct Answer: A) Yes. Explanation: Since 5 > 2 is True, the ternary expression evaluates to "Yes".
222What are inline conditionals useful for? A) Defining complex multiline loops B) Concise value assignment based on a condition C) Exception handling D) Bitwise operations
Correct Answer: B) Concise value assignment based on a condition. Explanation: They allow you to assign one of two values to a variable in a single, readable line of code.
223What happens if the condition in a ternary operator evaluates to False? A) The expression raises an error B) It returns the else expression value C) It returns None D) It skips execution
Correct Answer: B) It returns the else expression value. Explanation: The ternary structure evaluates the alternative branch when the condition is falsy.
224What is the output of [x * 2 for x in range(3)]? A) [0, 2, 4] B) [2, 4, 6] C) (0, 2, 4) D) {0, 2, 4}
Correct Answer: A) [0, 2, 4]. Explanation: A list comprehension evaluates x * 2 for each item generated by range(3) (0, 1, 2), returning a new list.
225Which of the following is a valid list comprehension with a condition (filtering)? A) [x for x in range(5) if x % 2 == 0] B) [x if x % 2 == 0 for x in range(5)] C) [for x in range(5): x] D) [x range(5) filter x]
Correct Answer: A) [x for x in range(5) if x % 2 == 0]. Explanation: In list comprehensions, the optional if condition filters items after the iteration expression.
226What does the enumerate() function return when iterating over a list? A) Just the items B) Pairs of (index, item) as tuples C) Just the indices D) A dictionary
Correct Answer: B) Pairs of (index, item) as tuples. Explanation: enumerate() adds a counter to an iterable, yielding index-value pairs during iteration.
227What is the output of list(enumerate(['a', 'b']))? A) [(0, 'a'), (1, 'b')] B) [('a', 0), ('b', 1)] C) [0, 1] D) [('a', 'b')]
Correct Answer: A) [(0, 'a'), (1, 'b')]. Explanation: By default, enumerate starts counting at index 0 and yields tuples of (index, value).
228What does the zip() function do when combining two lists of unequal length? A) Raises an error B) Truncates to the length of the shortest iterable C) Pads the shorter list with None D) Repeats the shorter list
Correct Answer: B) Truncates to the length of the shortest iterable. Explanation: zip() stops aggregating as soon as the shortest input iterable is exhausted.
229What is the result of a, b = 10, 20? A) a=10, b=20 B) a=20, b=10 C) A syntax error D) A tuple (10, 20) assigned to both
Correct Answer: A) a=10, b=20. Explanation: Python supports multiple assignment by unpacking the values on the right-hand side into the corresponding variables on the left.
230How do you swap the values of variables a and b in a single Pythonic line? A) a, b = b, a B) swap(a, b) C) a = b = a D) a, b = a, b
Correct Answer: A) a, b = b, a. Explanation: Tuple packing and unpacking on the left and right sides allows clean variable swapping without a temporary variable.
231What happens if you try to unpack a, b = [1, 2, 3]? A) a=1, b=2 B) ValueError C) TypeError D) a=1, b=[2, 3]
Correct Answer: B) ValueError. Explanation: Python raises a ValueError if the number of variables on the left does not match the number of elements in the unpacked sequence.
232What is the difference between list.sort() and sorted(list)? A) .sort() modifies the list in-place and returns None; sorted() returns a new sorted list leaving the original unchanged. B) They do the exact same thing. C) sorted() only works on tuples. D) .sort() returns a new list.
Correct Answer: A) .sort() modifies the list in-place and returns None; sorted() returns a new sorted list leaving the original unchanged. Explanation: This is a classic PCEP exam distinction regarding mutability and return values.
233What is the output of lst = [3, 1, 2]; x = lst.sort(); print(x)? A) [1, 2, 3] B) None C) [3, 1, 2] D) Error
Correct Answer: B) None. Explanation: Because .sort() sorts in-place, it returns None. Printing x will output None, while lst itself is now sorted.
234What is the output of a = [1, 2]; b = a; b.append(3); print(len(a))? A) 2 B) 3 C) Error D) None
Correct Answer: B) 3. Explanation: Assignment (b = a) copies the reference, not the list itself. Both a and b point to the exact same list object in memory, so modifying b affects a.
235How do you create an independent shallow copy of a list lst1? A) lst2 = lst1 B) lst2 = lst1.copy() C) lst2 = list(lst1) D) Both B and C
Correct Answer: D) Both B and C. Explanation: Both .copy() and list() (or slicing lst1[:]) create a new list object with the same elements, breaking the reference link.
236What is the output of a = [1, 2]; b = a.copy(); b.append(3); print(a)? A) [1, 2] B) [1, 2, 3] C) Error D) [3, 1, 2]
Correct Answer: A) [1, 2]. Explanation: Because b is a separate copy created via .copy(), appending to b does not alter a.
237Which of the following exception handling syntactically catches multiple specific exceptions in a single except block? A) except (ValueError, TypeError): B) except ValueError, TypeError: C) except [ValueError, TypeError]: D) except ValueError or TypeError
:Correct Answer: A) except (ValueError, TypeError):. Explanation: Multiple exception classes must be grouped inside a tuple parenthesis within the except clause.
238What is the output of try: int("abc") except ValueError: print("Val") except Exception: print("Gen")? A) Val B) Gen C) ValGen D) Error
Correct Answer: A) Val. Explanation: Python checks except blocks from top to bottom and executes the first matching exception handler, skipping subsequent ones.
239Why is placing a bare except: block before specific exception blocks a bad practice? A) It raises a SyntaxError B) It catches all exceptions (including system exits) and masks specific errors prematurely C) It runs slower D) It only catches integers
Correct Answer: B) It catches all exceptions (including system exits) and masks specific errors prematurely. Explanation: Specific exception handlers should always appear before broad or bare except clauses.
240What will this nested loop output? for i in range(2): for j in range(2): print(i, j, end=" ") A) 0 0 0 1 1 0 1 1 B) 0 1 2 3 C) 0 0 1 1 D) 1 1 2 2
Correct Answer: A) 0 0 0 1 1 0 1 1. Explanation: For every outer loop iteration (i), the inner loop runs completely through its range (j goes 0 then 1).
241What is the output of print(type(range(5)))? A) <class 'list'> B) <class 'tuple'> C) <class 'range'> D) <class 'iterable'>
Correct Answer: C) <class 'range'>. Explanation: range() returns a specialized immutable sequence object representing an arithmetic progression, not a materialized list.
242What keyword is used to define a user-defined function in Python? A) func B) define C) def D) function
Correct Answer: C) def. Explanation: The def keyword introduces a function definition, followed by the function name and parentheses.
243What is the return value of a function that does not contain a return statement? A) 0 B) False C) None D) Error
Correct Answer: C) None. Explanation: Functions without an explicit return statement implicitly return the None singleton object.
244Which keyword allows a function to modify a variable defined in the global scope? A) global B) nonlocal C) shared D) mutable
Correct Answer: A) global. Explanation: The global keyword informs the interpreter that a variable assignment inside a function refers to the global namespace.
245What happens when a mutable object like a list is used as a default parameter value in a function definition? A) It creates a new list on every call B) It shares the same list object across multiple calls C) It raises a SyntaxError D) It turns the list into a tuple
Correct Answer: B) It shares the same list object across multiple calls. Explanation: Default arguments are evaluated only once when the function is defined, retaining mutable state across calls.
246What syntax allows a function to accept an arbitrary number of positional arguments? A) *args B) **kwargs C) &args D) #args
Correct Answer: A) *args. Explanation: The * operator packs any extra positional arguments into a tuple named args.
247What syntax allows a function to accept an arbitrary number of keyword arguments? A) *args B) **kwargs C) &kwargs D) #kwargs
Correct Answer: B) **kwargs. Explanation: The ** operator packs extra keyword arguments into a dictionary.
248Which exception is raised when you try to divide a number by zero? A) ArithmeticError B) ValueError C) ZeroDivisionError D) DivisionError
Correct Answer: C) ZeroDivisionError. Explanation: Python raises the most specific exception class available for division by zero errors.
249Which exception class is the base class for all built-in non-system-exiting exceptions? A) BaseException B) Exception C) StandardError D) SystemError
Correct Answer: B) Exception. Explanation: Most user-defined and standard built-in exceptions inherit from Exception, whereas BaseException includes system exits and interrupts.
250What is the purpose of the else block in a try-except statement? A) It runs if an exception occurs B) It runs only if no exceptions occur in the try block C) It runs regardless of exceptions D) It replaces the finally block
Correct Answer: B) It runs only if no exceptions occur in the try block. Explanation: The else clause executes after the try block completes successfully without raising any exceptions.
251When is the finally block executed in a try-except-finally structure? A) Only when an exception occurs B) Only when no exceptions occur C) Always, regardless of whether an exception occurred or was handled D) Only when explicitly called
Correct Answer: C) Always, regardless of whether an exception occurred or was handled. Explanation: The finally block is guaranteed to execute for cleanup tasks like releasing resources.
252Which exception is raised when a local or global variable name is not found in the current scope? A) LookupError B) NameError C) KeyError D) AttributeError
Correct Answer: B) NameError. Explanation: NameError occurs when an identifier cannot be resolved in the local or global namespaces.
253Which built-in exception is raised when a sequence subscript is out of range? A) KeyError B) TypeError C) IndexError D) ValueError
Correct Answer: C) IndexError. Explanation: IndexError is raised when a list, tuple, or string index is outside its valid integer range.
254Which built-in exception is raised when a dictionary key is not found? A) IndexError B) LookupError C) KeyError D) NameError
Correct Answer: C) KeyError. Explanation: KeyError is raised when a mapping (dictionary) key is missing from the collection.
255How do you catch multiple specific exception classes in a single except clause? A) except ValueError, TypeError: B) except (ValueError, TypeError): C) except [ValueError, TypeError]: D) except ValueError or TypeError
Correct Answer: B) except (ValueError, TypeError): Explanation: Multiple exception types must be grouped inside a tuple parenthesized expression within the except statement.
256Why is placing a bare except: block before specific exception handlers considered poor practice? A) It causes a SyntaxError B) It catches system exits and masks specific errors prematurely C) It runs slower D) It only catches integers
Correct Answer: B) It catches all exceptions and masks specific errors prematurely. Explanation: Broad or bare except clauses should always follow specific exception handlers to avoid hiding unexpected bugs.
257What is the term for a function calling itself during execution? A) Iteration B) Recursion C) Encapsulation D) Delegation
Correct Answer: B) Recursion. Explanation: Recursion occurs when a function defines a call to itself, requiring a well-defined base case to terminate.
258What error occurs if a recursive function lacks a proper base case? A) SyntaxError B) RecursionError C) TypeError D) IndexError
Correct Answer: B) RecursionError. Explanation: Python limits the maximum recursion depth and raises a RecursionError when exceeded.
259What is the difference between parameters and arguments? A) They are identical terms B) Parameters are defined in the function signature, while arguments are the actual values passed during a call C) Arguments are variables, parameters are constants D) Parameters only exist inside loops
Correct Answer: B) Parameters are defined in the function signature, while arguments are the actual values passed during a call. Explanation: Parameters act as placeholders in the function definition, whereas arguments supply the concrete inputs.
260What is the output of a function that executes a return statement without any expression? A) 0 B) False C) None D) Error
Correct Answer: C) None. Explanation: A bare return statement implicitly returns the None object to the caller.
261Which exception base class groups both IndexError and KeyError under a common parent? A) ArithmeticError B) LookupError C) ValueError D) Exception
Correct Answer: B) LookupError. Explanation: LookupError is the base class for IndexError and KeyError, representing indexing and mapping access failures.
262What is the output of the following slice operation? word = "Computer"; print(word[
-2]) A) "epuc" B) "rpum" C) "treu" D) "Cptr"__Correct Answer: A) "epuc". Explanation: A negative step without explicit start and stop indices reverses the entire string first, then steps by 2 starting from the last character ('r', 'u', 'p', 'e').
What is the output of the following slice operation? letters = ['a', 'b', 'c', 'd', 'e']; print(letters[3:1:1]) A) ['d', 'c'] B) ['c', 'd'] C) [] D) ['d', 'c', 'b']__Correct Answer: C) []. Explanation: When using a positive step (+1), if the start index (3) is greater than or equal to the stop index (1), the resulting slice is empty because the direction of traversal conflicts with the step sign.
What is the output of the following slice operation? text = "DataScience"; print(text[10:2:-2]) A) "ecae" B) "enac" C) "eSn" D) "cnae"__Correct Answer: B) "enac". Explanation: Starting at index 10 ('e') and moving backwards with a step of -2 up to, but not including, index 2 ('t'), it picks indices 10, 8, 6, and 4 corresponding to characters 'e', 'n', 'a', and 'c'.