Data Science with Python Practice Exam Questions, Exams of Technology

A practice exam for data science with python, featuring multiple-choice questions and detailed explanations. It covers fundamental python data types, operators, control flow, list comprehensions, dictionary methods, set operations, and scope. Additionally, it includes questions on numpy, pandas, and matplotlib, making it a valuable resource for students and professionals preparing for data science roles. The exam tests knowledge of array creation, broadcasting rules, data manipulation, and visualization techniques. It also assesses understanding of pandas dataframes, json file reading, data cleaning, and aggregation functions. Finally, it covers matplotlib objects and seaborn functions for data visualization, providing a comprehensive review of essential data science concepts and tools in python.

Typology: Exams

2025/2026

Available from 12/06/2025

shilpi-jain-1
shilpi-jain-1 🇮🇳

4.2

(5)

29K documents

1 / 109

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Science with Python Practice Exam
**Question 1.** Which of the following Python data types is immutable?
A) list
B) dict
C) set
D) tuple
Answer: D
Explanation: Tuples cannot be altered after creation, whereas lists, dictionaries,
and sets are mutable.
**Question 2.** What is the output of `type(5 / 2)` in Python 3?
A) `<class 'int'>`
B) `<class 'float'>`
C) `<class 'long'>`
D) `<class 'decimal'>`
Answer: B
Explanation: The `/` operator performs true division and always returns a float.
**Question 3.** Which operator has the highest precedence in Python?
A) `or`
B) `and`
C) `not`
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Data Science with Python Practice Exam Questions and more Exams Technology in PDF only on Docsity!

Question 1. Which of the following Python data types is immutable? A) list B) dict C) set D) tuple Answer: D Explanation: Tuples cannot be altered after creation, whereas lists, dictionaries, and sets are mutable. Question 2. What is the output of type(5 / 2) in Python 3? A) <class 'int'> B) <class 'float'> C) <class 'long'> D) <class 'decimal'> Answer: B Explanation: The / operator performs true division and always returns a float. Question 3. Which operator has the highest precedence in Python? A) or B) and C) not

D) **

Answer: D Explanation: Exponentiation (**) is evaluated before unary not, logical and, and or. Question 4. Which statement correctly tests whether a variable x is both greater than 10 and less than 20? A) if 10 < x and x < 20: B) if (x > 10) & (x < 20): C) if 10 < x && x < 20: D) if x > 10 & x < 20: Answer: A Explanation: The logical and combines two boolean expressions; & performs bitwise AND and && is not a Python operator. Question 5. What does the continue statement do inside a for loop? A) Terminates the loop entirely. B) Skips the current iteration and proceeds to the next. C) Restarts the loop from the beginning. D) Does nothing. Answer: B

Question 8. Which set operation returns elements that are in set A but not in set B? A) A & B B) A | B C) A - B D) A ^ B Answer: C Explanation: The difference operator - yields items only in the first set. Question 9. What is the scope of a variable defined inside a function but declared with the keyword global? A) Local to the function only. B) Enclosing scope. C) Global (module) scope. D) Built‑in scope. Answer: C Explanation: Using global tells Python to refer to the variable in the module’s global namespace. Question 10. Which of the following correctly defines an anonymous function that adds 5 to its argument? A) lambda x: x + 5

B) def lambda x: x + 5 C) lambda(x): x + 5 D) def add5(x): return x + 5 Answer: A Explanation: lambda creates an anonymous function; the syntax is lambda arguments: expression. Question 11. Which import statement correctly imports the sqrt function from the math module with an alias sq? A) import math.sqrt as sq B) from math import sqrt as sq C) import sqrt from math as sq D) from math import * as sq Answer: B Explanation: from module import name as alias is the proper syntax. Question 12. What will be printed by the following code?

try: int('a') except ValueError: **Question 14.** Which NumPy function creates an array of ten evenly spaced numbers between 0 and 1 inclusive? A) `np.arange(0,1,0.1)` B) `np.linspace(0,1,10)` C) `np.zeros(10)` D) `np.ones(10)` Answer: B Explanation: `linspace(start, stop, num)` returns `num` equally spaced points including the endpoints. **Question 15.** If `a = np.array([1,2,3])` and `b = np.array([4,5,6])`, what is the result of `a * b`? A) `[5,7,9]` B) `[4,10,18]` C) `[5,7,9]` (matrix multiplication) D) `Error` Answer: B Explanation: NumPy performs element‑wise multiplication by default. **Question 16.** Which broadcasting rule allows adding a 1‑D array of shape `(3,)` to a 2‑D array of shape `(5,3)`? A) The 1‑D array is automatically reshaped to `(1,3)`. B) The 1‑D array is tiled to `(5,3)`. C) Both A and B are valid interpretations of broadcasting. D) Broadcasting is not possible in this case. Answer: C Explanation: NumPy treats the 1‑D array as `(1,3)` and then virtually repeats it across the first dimension. **Question 17.** What is the shape of an array created by `np.zeros((2,3,4))`? A) `(2, 3, 4)` B) `(4, 3, 2)` C) `(2, 4, 3)` D) `(3, 2, 4)` Answer: A Explanation: The `shape` attribute matches the dimensions supplied to `zeros`. **Question 18.** Which NumPy function computes the dot product of two 2‑D arrays `A` (shape 2×3) and `B` (shape 3×4)? A) `np.multiply(A, B)` B) `np.dot(A, B)` C) `A @ B` D) Both B and C Answer: D **Question 21.** Which Pandas method reads a JSON file into a DataFrame? A) `pd.read_json()` B) `pd.read_csv()` C) `pd.read_excel()` D) `pd.read_html()` Answer: A Explanation: `read_json` parses JSON formatted data directly into a DataFrame. **Question 22.** After executing `df.dropna(inplace=True)`, what happens to `df`? A) Rows with any missing values are removed permanently. B) Missing values are replaced with zeros. C) The operation returns a new DataFrame leaving `df` unchanged. D) Only columns with missing values are dropped. Answer: A Explanation: `dropna` removes rows (or columns) containing NaN; `inplace=True` modifies the original object. **Question 23.** Which Pandas function converts a categorical column `col` to one‑hot encoded columns? A) `pd.get_dummies(df['col'])` B) `df['col'].astype('category').cat.codes` C) `df['col'].apply(LabelEncoder())` D) `df['col'].map({})` Answer: A Explanation: `get_dummies` creates binary columns for each category. **Question 24.** What does the `groupby('city').agg(['mean','max'])` operation return? A) A DataFrame with rows grouped by city and columns showing mean and max of each numeric column. B) A Series with aggregated values. C) A pivot table. D) An error because `agg` expects a dictionary. Answer: A Explanation: `groupby` followed by `agg` computes the specified aggregation functions for each group. **Question 25.** Which method reshapes a DataFrame from long to wide format using unique values of column `type` as new columns? A) `df.melt(id_vars='id')` B) `df.pivot(index='id', columns='type', values='value')` C) `df.stack()` D) `df.unstack()` **Question 28.** What does `plt.hist(data, bins=20, density=True)` do? A) Plots a histogram with 20 bins and normalizes the area to 1. B) Plots a bar chart with 20 bars. C) Plots a histogram with counts, not densities. D) Returns the raw bin counts. Answer: A Explanation: `density=True` scales the histogram so that the integral of the bars equals 1. **Question 29.** In Seaborn, which function creates a matrix of pairwise scatter plots for a DataFrame `df`? A) `sns.heatmap(df)` B) `sns.pairplot(df)` C) `sns.boxplot(df)` D) `sns.lmplot(df)` Answer: B Explanation: `pairplot` draws a grid of scatter plots (and histograms on the diagonal) for each variable pair. **Question 30.** Which metric is most appropriate for evaluating the performance of a regression model? A) Accuracy B) Precision C) Mean Squared Error D) ROC AUC Answer: C Explanation: Regression deals with continuous outputs; MSE measures average squared prediction error. **Question 31.** In scikit‑learn, which class implements k‑fold cross‑validation? A) `KFold` B) `CrossValidator` C) `GridSearchCV` D) `StratifiedShuffleSplit` Answer: A Explanation: `KFold` provides simple k‑fold splitting; `StratifiedKFold` is a variant for classification. **Question 32.** What is the purpose of feature scaling before applying K‑Nearest Neighbors? A) To reduce dimensionality. B) To ensure all features contribute equally to distance calculations. C) To encode categorical variables. Explanation: The sigmoid function squashes any real number to the (0,1) interval, suitable for binary probabilities. **Question 35.** Which metric is defined as `TP / (TP + FP)`? A) Recall B) Precision C) Accuracy D) F1 Score Answer: B Explanation: Precision measures the proportion of positive predictions that are correct. **Question 36.** What does the ROC curve plot? A) Precision vs. Recall B) True Positive Rate vs. False Positive Rate C) Accuracy vs. Threshold D) Loss vs. Epochs Answer: B Explanation: ROC visualizes the trade‑off between sensitivity (TPR) and 1 ‑specificity (FPR). **Question 37.** Which scikit‑learn function splits data into training and test sets while preserving class proportions? A) `train_test_split` with `stratify=y` B) `cross_val_score` C) `KFold` D) `ShuffleSplit` Answer: A Explanation: Setting `stratify=y` ensures the split maintains the same class distribution. **Question 38.** Which PCA step reduces dimensionality while preserving maximal variance? A) Selecting components with largest eigenvalues. B) Selecting components with smallest eigenvalues. C) Randomly selecting components. D) Using the first few original features. Answer: A Explanation: Eigenvectors associated with the largest eigenvalues capture the most variance. **Question 39.** In a decision tree, which impurity measure is based on the probability of misclassifying a randomly chosen element? A) Gini impurity Explanation: `axis=0` aggregates along rows, yielding column‑wise means. **Question 42.** Which Pandas method returns the number of unique values in column `col`? A) `df[col].unique()` B) `df[col].nunique()` C) `df[col].value_counts()` D) `df[col].count()` Answer: B Explanation: `nunique` directly gives the count of distinct elements. **Question 43.** How can you convert a column of strings `['1','2','3']` to integers in a DataFrame `df`? A) `df['col'].astype(int)` B) `df['col'].astype('int64')` C) `pd.to_numeric(df['col'])` D) All of the above Answer: D Explanation: All listed approaches coerce string numbers to integer dtype. **Question 44.** Which NumPy function returns the indices that would sort an array? A) `np.sort` B) `np.argsort` C) `np.lexsort` D) `np.searchsorted` Answer: B Explanation: `argsort` yields the permutation indices that sort the array. **Question 45.** In Matplotlib, which command adds a legend to the current axes? A) `plt.title('Legend')` B) `plt.legend()` C) `plt.label()` D) `plt.annotate()` Answer: B Explanation: `legend()` creates a legend based on labeled plot elements. **Question 46.** Which Seaborn function is ideal for visualizing the distribution of a single continuous variable? A) `sns.boxplot` B) `sns.histplot` C) `sns.barplot` D) `sns.heatmap`