Python Basics for Data Science MCQ Questions and Answers Part – 1
Python Basics for Data Science MCQ Questions and Answers Part – 2
Section 1: Python Basics (1-10)
-
What is the correct way to declare a function in Python?
- a)
function myFunc(): - b)
def myFunc(): - c)
define myFunc(): - d)
func myFunc():
Answer: b)def myFunc():
- a)
-
What is the default return type of the
input()function?- a) Integer
- b) Float
- c) String
- d) List
Answer: c) String
-
How do you swap values of two variables
aandbin Python?- a)
a, b = b, a - b)
swap(a, b) - c)
a = b; b = a - d)
swap_values(a, b)
Answer: a)a, b = b, a
- a)
-
What will
print(bool([]))return?- a)
True - b)
False - c)
None - d)
Error
Answer: b)False
- a)
-
What keyword is used to define a class in Python?
- a)
define - b)
class - c)
structure - d)
object
Answer: b)class
- a)
-
What will be the output of
print(10 // 3)?- a)
3.33 - b)
3 - c)
4 - d)
Error
Answer: b)3
- a)
-
What method is used to remove an element from a list by its value?
- a)
del list[index] - b)
list.remove(value) - c)
list.pop(index) - d)
list.delete(value)
Answer: b)list.remove(value)
- a)
-
How do you check if a key exists in a dictionary?
- a)
dict.has_key(key) - b)
if key in dict: - c)
dict.exists(key) - d)
if key present in dict:
Answer: b)if key in dict:
- a)
-
What does
bool({})return?- a)
True - b)
False - c)
None - d)
Error
Answer: b)False
- a)
-
What operator is used for exponentiation in Python?
- a)
^ - b)
** - c)
exp() - d)
//
Answer: b)**
Section 2: NumPy (11-20)
- How do you create a NumPy array with values from 0 to 9?
- a)
np.arange(10) - b)
np.range(10) - c)
np.array([0:10]) - d)
np.linspace(0, 9, 10)
Answer: a)np.arange(10)
- What function returns the number of dimensions in a NumPy array?
- a)
array.shape - b)
array.ndim - c)
array.size - d)
array.dim()
Answer: b)array.ndim
- What function is used to calculate the mean of a NumPy array?
- a)
array.avg() - b)
np.mean(array) - c)
np.average(array) - d)
array.mean()
Answer: b)np.mean(array)
- How do you create a 3×3 identity matrix in NumPy?
- a)
np.identity(3,3) - b)
np.ones((3,3)) - c)
np.eye(3) - d)
np.matrix(3)
Answer: c)np.eye(3)
- What function computes the sum of all elements in a NumPy array?
- a)
array.sum() - b)
np.total(array) - c)
np.sum(array) - d)
np.add(array)
Answer: c)np.sum(array)
- What is the correct syntax to reshape a NumPy array?
- a)
array.shape(3,3) - b)
array.reshape((3,3)) - c)
np.reshape(array, (3,3)) - d)
array.resize((3,3))
Answer: c)np.reshape(array, (3,3))
- How do you find the maximum value in a NumPy array?
- a)
array.max() - b)
np.max(array) - c)
np.maximum(array) - d)
array.maximum()
Answer: b)np.max(array)
- What function is used to concatenate two NumPy arrays?
- a)
np.append() - b)
np.concatenate() - c)
np.stack() - d)
np.join()
Answer: b)np.concatenate()
- What function is used to compute the dot product of two NumPy arrays?
- a)
np.product() - b)
np.dot() - c)
np.cross() - d)
np.multiply()
Answer: b)np.dot()
- What function is used to create an array filled with ones?
- a)
np.one() - b)
np.ones() - c)
np.fill(1) - d)
np.unit()
Answer: b)np.ones()
Section 3: Pandas (21-30)
- How do you load a CSV file into a Pandas DataFrame?
- a)
pd.load_csv('file.csv') - b)
pd.open_csv('file.csv') - c)
pd.read_csv('file.csv') - d)
pd.import_csv('file.csv')
Answer: c)pd.read_csv('file.csv')
- How do you check for missing values in a DataFrame?
- a)
df.has_null() - b)
df.find_missing() - c)
df.isnull() - d)
df.missing_values()
Answer: c)df.isnull()
- What function is used to drop missing values in Pandas?
- a)
df.remove_na() - b)
df.drop_empty() - c)
df.dropna() - d)
df.null_delete()
Answer: c)df.dropna()
- How do you select a specific column in a Pandas DataFrame?
- a)
df(column_name) - b)
df['column_name'] - c)
df.column_name() - d)
df.select_column('column_name')
Answer: b)df['column_name']
- How do you get the first five rows of a DataFrame?
- a)
df.show(5) - b)
df.head(5) - c)
df.top(5) - d)
df.view(5)
Answer: b)df.head(5)
- What function is used to get summary statistics of a DataFrame?
- a)
df.summary() - b)
df.stats() - c)
df.describe() - d)
df.details()
Answer: c)df.describe()
- How do you rename columns in Pandas?
- a)
df.modify_columns() - b)
df.rename(columns={'old_name': 'new_name'}) - c)
df.change_column_names() - d)
df.rename_column('old_name', 'new_name')
Answer: b)df.rename(columns={'old_name': 'new_name'})
- What function is used to sort a Pandas DataFrame?
- a)
df.sorting() - b)
df.arrange() - c)
df.sort_values(by='column_name') - d)
df.order_by('column_name')
Answer: c)df.sort_values(by='column_name')
- What does
df.dtypesreturn?
- a) Row names
- b) Missing values
- c) Data types of each column
- d) Column count
Answer: c) Data types of each column
- What function is used to reset index in a Pandas DataFrame?
- a)
df.set_index() - b)
df.remove_index() - c)
df.reset_index() - d)
df.index_reset()
Answer: c)df.reset_index()
Section 4: Matplotlib & Seaborn (31-40)
- What does
plt.xlabel("X-axis")do?
- a) Sets the x-axis label
- b) Sets the y-axis label
- c) Sets the plot title
- d) Adds a legend
Answer: a) Sets the x-axis label
- What function is used to display a histogram in Matplotlib?
- a)
plt.hist() - b)
plt.bar() - c)
plt.scatter() - d)
plt.line()
Answer: a)plt.hist()
- Which Seaborn function is used for a box plot?
- a)
sns.plot_box() - b)
sns.boxplot() - c)
sns.draw_box() - d)
sns.plot()
Answer: b)sns.boxplot()
- What function is used to show a legend in Matplotlib?
- a)
plt.names() - b)
plt.text() - c)
plt.legend() - d)
plt.labels()
Answer: c)plt.legend()
- What does
sns.heatmap()do?
- a) Creates a line plot
- b) Displays a scatter plot
- c) Visualizes correlations using color maps
- d) Draws a bar chart
Answer: c) Visualizes correlations using color maps
Section 5: Machine Learning & Deep Learning (41-50)
- What is the purpose of
train_test_split()in Scikit-learn?
- a) Splitting a dataset into training and test sets
- b) Splitting two DataFrames
- c) Filtering missing values
- d) Performing PCA
Answer: a) Splitting a dataset into training and test sets
- What type of machine learning algorithm is
LinearRegression()?
- a) Classification
- b) Regression
- c) Clustering
- d) Dimensionality reduction
Answer: b) Regression
- What is a confusion matrix used for?
- a) Regression problems
- b) Evaluating classification models
- c) Finding missing values
- d) Plotting data
Answer: b) Evaluating classification models
- What function is used for binary classification in neural networks?
- a) Softmax
- b) Sigmoid
- c) ReLU
- d) Tanh
Answer: b) Sigmoid
- What is overfitting in machine learning?
- a) Poor training performance
- b) Training accuracy is significantly higher than test accuracy
- c) Good model generalization
- d) Low variance
Answer: b) Training accuracy is significantly higher than test accuracy
- What is the primary function of an activation function in neural networks?
- a) Reduce training time
- b) Introduce non-linearity
- c) Store training data
- d) Optimize learning rate
Answer: b) Introduce non-linearity
- Which optimizer is commonly used in deep learning?
- a) Linear Regression
- b) Adam
- c) KNN
- d) SVM
Answer: b) Adam
- What is the main advantage of using ReLU activation function?
- a) Reduces training time
- b) Helps avoid vanishing gradient problem
- c) Ensures weights remain small
- d) Normalizes input data
Answer: b) Helps avoid vanishing gradient problem
- What does
dropouthelp prevent in deep learning models?
- a) Slow convergence
- b) Overfitting
- c) Vanishing gradient
- d) Underfitting
Answer: b) Overfitting
- What does
max_depthcontrol in a Decision Tree model?
- a) The number of nodes
- b) The maximum depth of the tree
- c) The number of classes
- d) The number of features
Answer: b) The maximum depth of the tree

