
































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 Exam 2026: Comprehensive University/College Practice Examination — Python Fundamentals, NumPy, Pandas, Data Cleaning, Data Analysis, Visualization, Statistics, Machine Learning & Problem Solving — 190 Multiple- Choice Questions with Answers & Detailed Rationales SECTION 1: Python Fundamentals (Questions 1–25) Question 1 Which of the following best describes the primary characteristic of Python that makes it suitable for data science? A. It requires explicit memory management by the programmer B. It is an interpreted, high-level language with extensive library support C. It compiles directly to machine code for maximum performance D. It enforces strict static typing at compile time Correct Answer : B Explanation: Python is interpreted and high-level, offering rich libraries like NumPy and pandas that accelerate data science workflows. Question 2 In Python, what is the primary difference between a list and a tuple?
A. Lists can only store numeric data, while tuples store any data type B. Tuples are mutable, while lists are immutable C. Lists are mutable, while tuples are immutable D. Tuples require more memory than lists for identical data Correct Answer : C Explanation: Lists allow modification after creation; tuples cannot be changed, making them suitable for fixed data collections. Question 3 A data analyst writes the following code: python x = [1, 2, 3, 4, 5] y = x[1:4] What is the value of y? A. [1, 2, 3] B. [2, 3, 4] C. [2, 3, 4, 5]
python print(type(3 / 2)) A. B. C. D. Correct Answer : B Explanation: The division operator / in Python 3 always returns a float, even when both operands are integers. Question 6 A data scientist needs to iterate over both indices and values of a list simultaneously. Which approach is most Pythonic? A. Using a for loop with manual index increment B. Using enumerate() in a for loop C. Using range() with list indexing D. Using a while loop with a counter variable
Correct Answer : B Explanation: enumerate() returns index-value pairs, providing clean and efficient iteration without manual counting. Question 7 What is the result of the following list comprehension? python [x**2 for x in range(4) if x % 2 == 0] A. [0, 4] B. [0, 1, 4, 9] C. [0, 2] D. [1, 4] Correct Answer : A Explanation: Only even numbers 0 and 2 satisfy the condition; squaring yields 0 and 4 respectively. Question 8 Which statement about Python functions is correct?
D. Error Correct Answer : C Explanation: The default value b=5 is used when only one argument is provided, so 3+5=8. Question 10 Which of the following is a mutable data type in Python? A. String B. Tuple C. List D. Frozenset Correct Answer : C Explanation: Lists are mutable, allowing in-place modification, while strings, tuples, and frozensets are immutable. Question 11 What does the zip() function accomplish in Python?
A. Compresses files for storage B. Combines multiple iterables element-wise into tuples C. Sorts elements across multiple lists D. Merges dictionaries into a single mapping Correct Answer : B Explanation: zip() pairs elements from multiple iterables, producing tuples until the shortest iterable is exhausted. Question 12 In Python, what is the purpose of the with statement? A. To define a new function scope B. To ensure proper resource management via context managers C. To create conditional execution blocks D. To declare global variables Correct Answer : B
B. KeyError C. ValueError D. TypeError Correct Answer : B Explanation: Missing dictionary keys raise KeyError; use .get() to avoid this exception. Question 15 A data scientist wants to catch multiple exception types in one handler. Which syntax is correct? A. except ValueError, TypeError: B. except (ValueError, TypeError): C. except ValueError and TypeError: D. except [ValueError, TypeError]: Correct Answer : B Explanation: Python requires exception types grouped in a tuple within parentheses to catch multiple exceptions.
Question 16 What is the output of the following code? python a = [1, 2, 3] b = a b.append(4) print(a) A. [1, 2, 3] B. [1, 2, 3, 4] C. [4] D. Error Correct Answer : B Explanation: Assignment binds b to the same list object as a, so appending through b modifies the shared list. Question 17 Which method creates a shallow copy of a list? A. list.copy()
Question 19 Given: python nums = [3, 1, 4, 1, 5] nums.sort(reverse=True) What is the resulting list? A. [1, 1, 3, 4, 5] B. [5, 4, 3, 1, 1] C. [5, 4, 3, 1, 1, 0] D. [3, 1, 4, 1, 5] Correct Answer : B Explanation: sort(reverse=True) sorts in descending order in place, yielding [5, 4, 3, 1, 1]. Question 20 What is the primary purpose of Python's init method? A. To destroy objects when no longer needed B. To initialize a newly created object's attributes
C. To define class-level constants D. To compare two objects for equality Correct Answer : B Explanation: init is the constructor method that initializes instance attributes when an object is created. Question 21 Which statement about Python's Global Interpreter Lock (GIL) is accurate? A. It allows true parallel execution of CPU-bound threads B. It prevents multiple threads from executing Python bytecode simultaneously C. It is only present in Python 2 D. It eliminates the need for multiprocessing Correct Answer : B Explanation: The GIL permits only one thread to execute Python bytecode at a time, limiting CPU-bound parallelism. Question 22
D. Error Correct Answer : B Explanation: String multiplication repeats the string; "data" repeated three times yields "datadatadata". Question 24 Which of the following correctly creates a dictionary comprehension? 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. dict{x: x2 for x in range(3)} Correct Answer : A Explanation: Dictionary comprehensions use curly braces with key:value pairs and a for clause. Question 25 What is the result of len(set([1, 2, 2, 3, 3, 3]))?
Correct Answer : A Explanation: Converting to a set removes duplicates, leaving {1, 2, 3} with three unique elements. SECTION 2: NumPy and Numerical Computing (Questions 26–50) Question 26 What is the primary advantage of NumPy arrays over Python lists for numerical computation? A. NumPy arrays can store mixed data types B. NumPy arrays support vectorized operations and efficient memory use C. NumPy arrays automatically sort their elements D. NumPy arrays are immutable Correct Answer : B
A. A 2x3 array filled with zeros B. A 3x2 array filled with zeros C. A 1D array of length 6 filled with zeros D. An empty array with undefined values Correct Answer : A Explanation: np.zeros((2, 3)) creates a 2-row, 3-column array initialized to zero. Question 29 Which NumPy function computes the dot product of two arrays? A. np.multiply() B. np.dot() C. np.cross() D. np.outer() Correct Answer : B
Explanation: np.dot() computes the dot product, essential for linear algebra operations. Question 30 A data scientist has a NumPy array arr of shape (4, 5). What is arr.shape[1]? A. 4 B. 5 C. 20 D. 1 Correct Answer : B Explanation: Shape returns (rows, columns); index 1 gives the number of columns, which is
Question 31 What is broadcasting in NumPy? A. Converting arrays to lists automatically B. Applying operations between arrays of different shapes under defined rules