
































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!

































Python for Data Science and AI Exam 2026: University & Professional Practice Test — Python Programming, NumPy, Pandas, Data Visualization, Machine Learning & AI Fundamentals — 190 Multiple-Choice Questions with Answers & Detailed Rationales SECTION 1: Python Fundamentals & Syntax (Questions 1–25) Question 1 Which Python data type is immutable? A. List B. Dictionary C. Tuple D. Set Correct Answer : C Explanation: Tuples cannot be modified after creation, unlike lists, dictionaries, and sets, which are mutable. Question 2 What is the output of type(3/2) in Python 3? A. B. C. D. Correct Answer : B
Explanation: The / operator always returns a float in Python 3, even for integer operands. Question 3 Which keyword creates an anonymous function in Python? A. def B. lambda C. func D. anonymous Correct Answer : B Explanation: lambda creates small anonymous functions inline without a formal def statement. Question 4 What does len({1, 2, 2, 3}) return? A. 4 B. 3 C. 2 D. Error Correct Answer : B Explanation: Sets store unique elements, so duplicates collapse, leaving three distinct values. Question 5
B. class C. value D. my-var Correct Answer : C Explanation: Variable names may start with an underscore and contain digits but cannot start with digits or use reserved keywords. Question 8 What does list(range(3)) produce? A. [1, 2, 3] B. [0, 1, 2] C. [0, 1, 2, 3] D. [3] Correct Answer : B Explanation: range(3) generates 0, 1, 2 — starting at zero and excluding the stop value. Question 9 Which method adds an element to the end of a list? A. insert() B. append() C. extend() D. push()
Correct Answer : B Explanation: append() adds a single element to the end; extend() adds multiple from an iterable. Question 10 What is the output of bool([])? A. True B. False C. None D. Error Correct Answer : B Explanation: Empty collections evaluate to False in boolean context; non-empty ones evaluate to True. Question 11 Which operator checks identity rather than equality? A. == B. is C. = D. != Correct Answer : B
What is the result of 5 // 2? A. 2. B. 2 C. 3 D. 1 Correct Answer : B Explanation: // performs floor division, discarding the fractional remainder. Question 15 Which structure is best for key-value storage? A. List B. Tuple C. Dictionary D. String Correct Answer : C Explanation: Dictionaries map unique keys to values, ideal for lookups by key. Question 16 What does the pass statement do? A. Skips the current iteration B. Exits the loop
C. Does nothing D. Raises an exception Correct Answer : C Explanation: pass is a null operation used as a placeholder where syntax requires a statement. Question 17 Which function returns the number of items in a list? A. count() B. size() C. len() D. length() Correct Answer : C Explanation: len() is the built-in function returning the length of sequences and collections. Question 18 What is the output of print(2 ** 3)? A. 6 B. 8 C. 9 D. 5
Question 21 Which method removes whitespace from both ends of a string? A. trim() B. strip() C. clean() D. chop() Correct Answer : B Explanation: strip() removes leading and trailing whitespace; lstrip() and rstrip() handle one side. Question 22 What is the output of any([False, False, True])? A. False B. True C. None D. Error Correct Answer : B Explanation: any() returns True if at least one element is truthy; here the last element qualifies. Question 23
Which is the correct way to define a function with a default argument? A. def f(x=5): B. def f(x:5): C. def f(x default 5): D. def f(x := 5): Correct Answer : A Explanation: Default values are assigned with = in the function signature, evaluated once at definition. Question 24 What does enumerate(['a','b']) yield? A. ['a','b'] B. (0,'a'), (1,'b') C. {'a':0,'b':1} D. Error Correct Answer : B Explanation: enumerate() pairs each element with its index, producing tuples of (index, value). Question 25 Which of these is a Python comment?
C. items() D. pairs() Correct Answer : A Explanation: keys() returns a view of dictionary keys; values() and items() return values and pairs. Question 28 What happens when accessing a missing dict key with d['x']? A. Returns None B. Raises KeyError C. Returns empty string D. Creates the key Correct Answer : B Explanation: Direct indexing raises KeyError; use get() to safely return a default instead. Question 29 Which is the output of sorted([3,1,2], reverse=True)? A. [1,2,3] B. [3,2,1] C. [2,1,3] D. [3,1,2]
Correct Answer : B Explanation: reverse=True sorts in descending order, yielding [3, 2, 1]. Question 30 What does a while loop require to terminate? A. A break statement only B. A condition that eventually becomes False C. A return statement D. A pass statement Correct Answer : B Explanation: A while loop runs until its condition evaluates to False (or a break exits it). Question 31 What is the result of {1,2} | {2,3}? A. {1,2} B. {2,3} C. {1,2,3} D. {2} Correct Answer : C Explanation: The | operator performs set union, combining all unique elements.
A. {x: x2 for x in range(3)} B. [x: x2 for x in range(3)] C. (x: x2 for x in range(3)) D. {x, x2 for x in range(3)} Correct Answer : A Explanation: Dict comprehensions use braces with key: value syntax inside the comprehension. Question 35 What is the output of sum([1,2,3], 10)? A. 6 B. 16 C. 10 D. 13 Correct Answer : B Explanation: The second argument provides a starting value added to the sum: 10 + 6 = 16. Question 36 Which keyword yields a value from a generator? A. return B. yield C. emit
D. send Correct Answer : B Explanation: yield pauses a generator, producing values lazily on each iteration. Question 37 What does d.get('k', 0) return if 'k' is absent? A. KeyError B. None C. 0 D. Empty string Correct Answer : C Explanation: The second argument to get() is returned when the key is not found. Question 38 Which is the output of set([1,1,2])? A. {1,1,2} B. {1,2} C. [1,2] D. (1,2) Correct Answer : B
A. Reversed list B. None C. New list D. Boolean Correct Answer : B Explanation: reverse() reverses in place and returns None; use reversed() for a new iterator. Question 42 Which loops over dict key-value pairs? A. for k in d: B. for k,v in d.items(): C. for v in d.values(): D. for i in range(len(d)): Correct Answer : B Explanation: items() yields (key, value) tuples, allowing unpacking in the loop. Question 43 What is the output of [i for i in range(5) if i%2==0]? A. [1,3] B. [0,2,4] C. [0,1,2] D. [2,4]
Correct Answer : B Explanation: The condition keeps even numbers from 0 to 4, yielding [0, 2, 4]. Question 44 Which method merges another dictionary into an existing one in-place? A. merge() B. update() C. combine() D. join() Correct Answer : B Explanation: update() adds or overwrites key-value pairs from another mapping. Question 45 What does frozenset provide over set? A. Ordering B. Immutability C. Indexing D. Duplicates Correct Answer : B