Python Data Science Practice Exam Questions, Exams of Technology

A set of practice exam questions focused on python for data science. It covers topics such as variable assignment, data structures, dictionary comprehensions, list comprehensions, control flow statements, lambda functions, the legb rule, module importing, exception handling, file i/o, virtual environments, package management with pip, numpy arrays, and pandas dataframes. Each question includes a detailed explanation of the correct answer, making it a valuable resource for exam preparation and reinforcing key concepts in python programming for data science. The questions are designed to test understanding of fundamental python concepts and their application in data science contexts, providing a comprehensive review of essential topics.

Typology: Exams

2025/2026

Available from 12/22/2025

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

4.2

(5)

29K documents

1 / 85

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python A Z Python For Data Science With
Real Exercises Certificate Practice Exam
Question 1. **Which of the following statements about Python variable assignment is true?**
A) Variables must be declared with a type keyword.
B) Assignment creates a reference to an object.
C) Assignment copies the object’s value into a new memory location.
D) Variable names can start with a digit.
Answer: B
Explanation: In Python, assigning a value to a name binds the name to the existing object; no
copy of the object is made.
Question 2. **What is the output of `type(3.14)`?**
A) `<class 'int'>`
B) `<class 'float'>`
C) `<class 'str'>`
D) `<class 'bool'>`
Answer: B
Explanation: `3.14` is a floatingpoint literal, so its type is `float`.
Question 3. **Which data structure guarantees order, allows duplicates, and is mutable?**
A) tuple
B) set
C) list
D) frozenset
Answer: C
Explanation: Lists preserve insertion order, can contain duplicate elements, and support item
assignment.
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

Partial preview of the text

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

Real Exercises Certificate Practice Exam

Question 1. Which of the following statements about Python variable assignment is true? A) Variables must be declared with a type keyword. B) Assignment creates a reference to an object. C) Assignment copies the object’s value into a new memory location. D) Variable names can start with a digit. Answer: B Explanation: In Python, assigning a value to a name binds the name to the existing object; no copy of the object is made. Question 2. What is the output of type(3.14)? A) <class 'int'> B) <class 'float'> C) <class 'str'> D) <class 'bool'> Answer: B Explanation: 3.14 is a floating‑point literal, so its type is float. Question 3. Which data structure guarantees order, allows duplicates, and is mutable? A) tuple B) set C) list D) frozenset Answer: C Explanation: Lists preserve insertion order, can contain duplicate elements, and support item assignment.

Real Exercises Certificate Practice Exam

Question 4. How can you create a dictionary comprehension that maps numbers 1‑5 to their squares? A) {x: x**2 for x in range(1,6)} B) [x: x**2 for x in range(1,6)] C) (x: x**2 for x in range(1,6)) D) {x, x**2 for x in range(1,6)} Answer: A Explanation: The syntax {key: value for item in iterable} creates a dictionary; range(1,6) generates 1‑5. Question 5. What does the following list comprehension produce? [[i*j for j in range(3)] for i in range(2)] A) [[0,0,0],[1,1,1]] B) [[0,0,0],[0,1,2]] C) [[0,0,0],[0,1,2,3]] D) [[0,0,0],[0,1,2]] Answer: D Explanation: For i=0 → [0*0,0*1,0*2]=[0,0,0]; for i=1 → [1*0,1*1,1*2]=[0,1,2]. Question 6. Which control flow statement will always execute at least once? A) if B) elif C) while with condition true at start D) do…while (Python equivalent) Answer: D

Real Exercises Certificate Practice Exam

Explanation: In Python 3, map returns a lazy map object; converting to list yields [2,4,6]. Question 10. Which of the following follows the LEGB rule for name resolution? A) Local → Enclosing → Global → Built‑in B) Global → Local → Enclosing → Built‑in C) Built‑in → Global → Enclosing → Local D) Enclosing → Local → Global → Built‑in Answer: A Explanation: Python searches in Local, then Enclosing (non‑local), then Global, then Built‑in namespaces. Question 11. **What will be printed?

def outer(): x = 5 def inner(): nonlocal x x = 10 inner() print(x) outer() ```** A) `5` B) `10` ## Real Exercises Certificate Practice Exam C) `NameError` D) `UnboundLocalError` Answer: B Explanation: `nonlocal` tells Python to use the variable from the nearest enclosing scope, allowing `inner` to modify `x`. Question 12. **Which statement correctly imports the `sqrt` function from the `math` module?** A) `import math.sqrt` B) `from math import sqrt` C) `import sqrt from math` D) `math import sqrt` Answer: B Explanation: `from module import name` imports a specific attribute. Question 13. **What is the purpose of the `finally` block in a `try/except/finally` construct?** A) Execute only if an exception occurs B) Execute only if no exception occurs C) Execute regardless of whether an exception was raised D) Suppress all exceptions Answer: C Explanation: `finally` runs after the `try` block finishes, whether an exception was caught or not. Question 14. **Which mode opens a file for reading binary data?** A) `'r'` ## Real Exercises Certificate Practice Exam B) `pip update numpy` C) `pip upgrade numpy` D) `pip reinstall numpy` Answer: A Explanation: `--upgrade` tells pip to install the newest version. Question 18. **Which NumPy function creates a 3 × 4 array filled with zeros?** A) `np.zeros((3,4))` B) `np.empty((3,4))` C) `np.full((3,4),0)` D) `np.zeros(3,4)` Answer: A Explanation: `np.zeros` expects a shape tuple; `np.zeros((3,4))` returns the desired array. Question 19. **What is the dtype of the array created by `np.array([1, 2, 3.0])`?** A) `int64` B) `float64` C) `object` D) `int32` Answer: B Explanation: Mixing integer and float literals forces promotion to the most precise type, which is `float64`. Question 20. **Which method returns a view of an array with a different shape without copying data?** ## Real Exercises Certificate Practice Exam A) `reshape()` B) `copy()` C) `flatten()` D) `astype()` Answer: A Explanation: `reshape` returns a new view when possible; no data is duplicated. Question 21. **What does the expression `arr[::2]` do?** A) Selects every second element starting from index 0 B) Selects every second element starting from index 1 C) Reverses the array D) Raises `IndexError` Answer: A Explanation: The slice step of 2 picks elements at indices 0,2,4,… Question 22. **Which NumPy operation will broadcast a (3,1) array `a` against a (3,4) array `b`?** A) `a + b` B) `a * b.T` C) `np.dot(a,b)` D) `np.linalg.inv(a)` Answer: A Explanation: Broadcasting expands the singleton dimension of `a` to match `b`’s shape, allowing element‑wise addition. ## Real Exercises Certificate Practice Exam Question 26. **Which of the following creates a 1‑D NumPy array with values from 0 to 9 inclusive?** A) `np.arange(10)` B) `np.linspace(0,9,10)` C) Both A and B D) Neither A nor B Answer: C Explanation: `np.arange(10)` produces `[0,…,9]`; `np.linspace(0,9,10)` also yields the same values. Question 27. **What is the shape of `np.zeros((2,3,4)).shape`?** A) `(2, 3, 4)` B) `(24,)` C) `(4, 3, 2)` D) `(2, 12)` Answer: A Explanation: The `shape` attribute reports the dimensions exactly as specified. Question 28. **Which Pandas object is a one‑dimensional labeled array?** A) DataFrame B) Series C) Panel D) Index Answer: B Explanation: A `Series` stores data with an associated index, acting as a labeled vector. ## Real Exercises Certificate Practice Exam Question 29. **How can you create a DataFrame from a dictionary `{'A':[1,2], 'B':[3,4]}`?** A) `pd.DataFrame({'A':[1,2], 'B':[3,4]})` B) `pd.Series({'A':[1,2], 'B':[3,4]})` C) `pd.DataFrame.from_dict({'A':[1,2], 'B':[3,4]})` D) Both A and C Answer: D Explanation: Both the constructor and `from_dict` accept a dict of column‑wise data. Question 30. **What does `df.loc[5]` do?** A) Selects the row with integer position 5 B) Selects the row whose index label equals 5 C) Selects column 5 D) Raises `KeyError` if label 5 not present Answer: B Explanation: `.loc` accesses rows/columns by label, not by integer position. Question 31. **Which method drops rows containing any missing values?** A) `df.dropna()` B) `df.fillna()` C) `df.isnull()` D) `df.replace()` Answer: A Explanation: `dropna` removes rows (or columns) where `NaN` appears. ## Real Exercises Certificate Practice Exam Question 35. **How do you compute the mean of column `salary` grouped by `department`?** A) `df.groupby('department')['salary'].mean()` B) `df['salary'].groupby('department').mean()` C) `df.groupby('salary')['department'].mean()` D) `df.mean('salary', by='department')` Answer: A Explanation: `groupby` followed by selecting the column and calling `mean` yields the grouped average. Question 36. **What does `df.pivot(index='date', columns='city', values='temp')` produce?** A) Reshapes data so each city becomes a column with temperature values indexed by date B) Merges rows with same date and city C) Drops duplicate rows D) Returns a long‑format DataFrame Answer: A Explanation: `pivot` creates a wide table where the specified `index` becomes rows, `columns` become new column labels, and `values` fill the cells. Question 37. **Which method resamples a time‑series DataFrame to monthly frequency, taking the sum of values?** A) `df.resample('M').sum()` B) `df.resample('monthly').aggregate('sum')` C) `df.groupby(pd.Grouper(freq='M')).sum()` D) Both A and C Answer: D Explanation: Both `resample('M')` and `groupby` with a `Grouper` achieve monthly aggregation. ## Real Exercises Certificate Practice Exam Question 38. **How can you read a CSV file named `data.csv` while parsing the column `date` as datetime?** A) `pd.read_csv('data.csv', parse_dates=['date'])` B) `pd.read_csv('data.csv', date_parser='date')` C) `pd.read_csv('data.csv', dtype={'date': datetime})` D) `pd.read_csv('data.csv', infer_datetime_format=True)` Answer: A Explanation: `parse_dates` tells pandas to interpret the listed columns as datetime objects. Question 39. **Which argument allows reading a large CSV in chunks of 100 000 rows?** A) `chunksize=100000` B) `iterator=100000` C) `batch=100000` D) `size=100000` Answer: A Explanation: `chunksize` returns an iterator yielding DataFrames of the given number of rows. Question 40. **What does `plt.figure(figsize=(8,4))` control?** A) Size of the plot in inches (width, height) B) DPI of the figure C) Number of subplots D) Color palette Answer: A Explanation: `figsize` sets the width and height of the figure in inches. ## Real Exercises Certificate Practice Exam Question 44. **Which Seaborn function creates a box plot showing distribution of `price` per `category`?** A) `sns.boxplot(x='category', y='price', data=df)` B) `sns.boxplot(data=df, x='price', hue='category')` C) `sns.barplot(x='category', y='price', data=df)` D) `sns.violinplot(x='price', y='category', data=df)` Answer: A Explanation: `boxplot` takes categorical variable on `x` and quantitative on `y`. Question 45. **What does `sns.heatmap(corr, annot=True, cmap='coolwarm')` display?** A) Correlation matrix as colored squares with numeric annotations B) Distribution of a single variable C) Pairwise scatter plots D) Time‑series line chart Answer: A Explanation: `heatmap` visualizes a 2‑D array; `annot=True` prints the values; the colormap defines colors. Question 46. **Which Seaborn function produces a pairwise relationship grid for all numeric columns?** A) `sns.pairplot(df)` B) `sns.jointplot(df)` C) `sns.distplot(df)` D) `sns.lmplot(df)` Answer: A Explanation: `pairplot` draws scatterplots (or histograms on the diagonal) for every variable pair. ## Real Exercises Certificate Practice Exam Question 47. **What is the default style used by Seaborn if you call `sns.set()`?** A) `darkgrid` B) `whitegrid` C) `ticks` D) `white` Answer: A Explanation: The default Seaborn aesthetic is `'darkgrid'`. Question 48. **Which plot type is most appropriate to compare the distribution of a continuous variable across several categories?** A) Box plot B) Line plot C) Scatter plot D) Bar plot Answer: A Explanation: Box plots summarize median, quartiles, and outliers for each category, making them ideal for distribution comparison. Question 49. **What does the term “over‑plotting” refer to in data visualization?** A) Too many data points overlapping, obscuring patterns B) Using too many colors C) Plotting on multiple axes simultaneously D) Adding excessive annotations Answer: A ## Real Exercises Certificate Practice Exam Answer: A Explanation: `StandardScaler` performs z‑score normalization. Question 53. **Which function splits data into training and test sets with 30 % reserved for testing?** A) `train_test_split(X, y, test_size=0.3)` B) `train_test_split(X, y, train_size=0.3)` C) `split_data(X, y, test=30)` D) `X_train, X_test = X[:70], X[70:]` Answer: A Explanation: `test_size` can be a float between 0 and 1 indicating the proportion for testing. Question 54. **Which assumption is NOT required for Linear Regression?** A) Linear relationship between predictors and target B) Homoscedasticity of residuals C) Multicollinearity among predictors must be high D) Errors are normally distributed Answer: C Explanation: High multicollinearity violates regression assumptions; we prefer low multicollinearity. Question 55. **What is the purpose of the `C` parameter in `LogisticRegression`?** A) Inverse of regularization strength (smaller values → stronger regularization) B) Controls the learning rate C) Number of iterations ## Real Exercises Certificate Practice Exam D) The cutoff probability for classification Answer: A Explanation: `C` is the inverse of the regularization term; decreasing `C` strengthens regularization. Question 56. **Which metric is appropriate for evaluating a regression model?** A) Mean Squared Error (MSE) B) Accuracy C) F1‑Score D) ROC‑AUC Answer: A Explanation: MSE quantifies average squared prediction error, suitable for continuous outcomes. Question 57. **What does a high R‑squared value indicate?** A) A large proportion of variance in the target is explained by the model B) The model is overfitting C) The residuals have high variance D) The model has many predictors Answer: A Explanation: R² = 1 – (SS_res / SS_tot); a value near 1 means the model captures most variability. Question 58. **Which Scikit‑learn function computes the confusion matrix?** A) `confusion_matrix(y_true, y_pred)` B) `classification_report(y_true, y_pred)`