














































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!















































Question 1 Which statement best describes Python? A. A compiled-only, statically typed programming language B. A markup language designed for web pages C. A high-level, general-purpose programming language that supports multiple programming paradigms D. A database query language Answer: C Rationale: Python is a high-level general-purpose language that supports procedural, object-oriented, and functional programming styles. Although Python implementations may
compile source code to bytecode internally, Python is not normally categorized as a compiled-only language. Question 2 What is the output of the following code? x = 10 y = 3 print(x // y) A. 3. B. 4 C. 3 D. 1 Answer: C Rationale: The // operator performs floor division. Ten divided by three is 3.333..., and floor division produces 3. Question 3 Which of the following is a valid Python variable name? A. 2value B. class
Answer: B Rationale: Python follows standard operator precedence. Multiplication occurs before addition, so 2 * 3 is evaluated first, producing 6, and then 5 is added to obtain 11. Question 6 Which operator is used for exponentiation in Python? A. ^ B. ^^ C. // D. **** Answer: D** Rationale: Python uses ** for exponentiation. For example, 2 ** 3 evaluates to 8. The ^ operator performs bitwise XOR. Question 7 What is the result of bool(0)?
A. True B. 0 C. False D. None Answer: C Rationale: Numeric zero is considered falsy in Python. Therefore, converting 0 to a Boolean produces False. Question 8 Which value represents the absence of a value in Python? A. empty B. void C. null D. None Answer: D Rationale: Python uses the singleton object None to represent the absence of a value or a null-like state. Question 9 What does the following code print? name = "Python"
Question 11 What is the result of: text = "Programming" print(text[0:4]) A. Prog B. Progr C. ogram D. Prog Answer: D Rationale: Python slicing includes the starting index but excludes the ending index. Therefore, indexes 0 through 3 produce Prog. Question 12 Which data structure is ordered, mutable, and allows duplicate values? A. Tuple B. Set C. List D. Frozen set Answer: C
Rationale: Lists maintain order, can be modified after creation, and can contain duplicate elements. Question 13 Which collection is immutable? A. List B. Dictionary C. Set D. Tuple Answer: D Rationale: Tuples cannot be modified after they are created. Lists, dictionaries, and sets are mutable. Question 14 What is the output? numbers = [1, 2, 3] numbers.append(4) print(numbers) A. [4, 1, 2, 3] B. [1, 2, 3]
C. It stores unique elements D. It requires numeric indexes Answer: C Rationale: Sets are designed to represent collections of unique hashable elements. Adding the same value repeatedly does not create duplicate entries. Question 17 Which syntax creates a dictionary? A. [("a", 1), ("b", 2)] B. ("a": 1, "b": 2) C. {"a": 1, "b": 2} D. {"a", "b"} Answer: C Rationale: Dictionaries use curly braces containing key-value pairs separated by colons. Question 18 What does the keys() dictionary method return? A. Dictionary values only B. Key-value pairs only
C. A view containing the dictionary's keys D. A sorted dictionary Answer: C Rationale: keys() provides a dynamic view of the dictionary's keys. Question 19 Which expression tests whether "Python" occurs inside a string variable text? A. text.has("Python") B. text.contains("Python") C. "Python" in text D. contains(text, "Python") Answer: C Rationale: Python uses the in operator to test membership in strings and many collection types. Question 20 What does len([10, 20, 30, 40]) return? A. 3 B. 4
Answer: C Rationale: elif means “else if.” It permits additional mutually exclusive conditions to be evaluated after an if condition fails. Question 23 What does the break statement do inside a loop? A. Skips the current iteration B. Restarts the loop C. Terminates the loop immediately D. Terminates the Python interpreter Answer: C Rationale: break exits the nearest enclosing loop immediately. Question 24 What does continue do? A. Terminates the program B. Terminates the loop permanently C. Skips the remainder of the current iteration and proceeds to the next iteration D. Repeats the current statement forever Answer: C
Rationale: continue causes the loop to proceed with its next iteration without executing the remaining statements in the current iteration. Question 25 What does this code print? for i in range(3): print(i) A. 1, 2, 3 B. 0, 1, 2, 3 C. 0, 1, 2 D. 1, 2 Answer: C Rationale: range(3) generates 0, 1, and 2. The stop value, 3, is excluded. Question 26 Which loop is most appropriate when the number of iterations is determined by an iterable? A. switch B. for
Answer: C Rationale: range(start, stop, step) begins at 2, increases by 2, and stops before 8. The resulting values are 2, 4, and 6. Question 29 What is the purpose of the pass statement? A. It exits a function B. It skips a loop permanently C. It acts as a placeholder where a statement is syntactically required D. It passes arguments between functions Answer: C Rationale: pass performs no operation. It is useful when a block is intentionally left empty during development or when a syntactic placeholder is needed. Question 30 What does else associated with a for loop execute when?
A. Every time the loop starts B. When the loop executes zero iterations only C. When the loop completes normally without encountering break D. Only when an exception occurs Answer: C Rationale: Python allows an else clause on loops. It executes after normal loop completion but is skipped when the loop terminates through break. Section IV — Functions Question 31 Which keyword is used to define a function? A. function B. define C. def D. func Answer: C Rationale: Python functions are defined using the def keyword followed by the function name and parameter list. Question 32
What is returned by a function that reaches the end without an explicit return? A. 0 B. False C. Empty string D. None Answer: D Rationale: Python functions implicitly return None when execution reaches the end without encountering a return statement with a value. Question 35 What is a default parameter value? A. A required argument B. A value automatically used when the caller does not provide that argument C. A global variable D. A constant created by Python Answer: B Rationale: Default parameters provide fallback values, making certain arguments optional when a function is called.
Question 36 Which syntax allows a function to receive an arbitrary number of positional arguments? A. **args B. *kwargs C. args D. &args Answer: C Rationale: *args collects additional positional arguments into a tuple. Question 37 Which syntax collects arbitrary keyword arguments? A. kwargs B. ****kwargs* C. &kwargs D. kwargs Answer: B Rationale: **kwargs collects additional keyword arguments into a dictionary.