Python Basics for Data Science MCQ Questions and Answers Part – 1

0
16
MCQs

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)

  1. 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():
  2. What is the default return type of the input() function?

    • a) Integer
    • b) Float
    • c) String
    • d) List
      Answer: c) String
  3. How do you swap values of two variables a and b in 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
  4. What will print(bool([])) return?

    • a) True
    • b) False
    • c) None
    • d) Error
      Answer: b) False
  5. What keyword is used to define a class in Python?

    • a) define
    • b) class
    • c) structure
    • d) object
      Answer: b) class
  6. What will be the output of print(10 // 3)?

    • a) 3.33
    • b) 3
    • c) 4
    • d) Error
      Answer: b) 3
  7. 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)
  8. 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:
  9. What does bool({}) return?

    • a) True
    • b) False
    • c) None
    • d) Error
      Answer: b) False
  10. What operator is used for exponentiation in Python?

  • a) ^
  • b) **
  • c) exp()
  • d) //
    Answer: b) **

Section 2: NumPy (11-20)

  1. 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)
  1. 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
  1. 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)
  1. 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)
  1. 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)
  1. 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))
  1. 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)
  1. 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()
  1. 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()
  1. 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)

  1. 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')
  1. 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()
  1. 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()
  1. 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']
  1. 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)
  1. 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()
  1. 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'})
  1. 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')
  1. What does df.dtypes return?
  • a) Row names
  • b) Missing values
  • c) Data types of each column
  • d) Column count
    Answer: c) Data types of each column
  1. 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)

  1. 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
  1. 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()
  1. 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()
  1. 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()
  1. 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)

  1. 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
  1. What type of machine learning algorithm is LinearRegression()?
  • a) Classification
  • b) Regression
  • c) Clustering
  • d) Dimensionality reduction
    Answer: b) Regression
  1. 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
  1. What function is used for binary classification in neural networks?
  • a) Softmax
  • b) Sigmoid
  • c) ReLU
  • d) Tanh
    Answer: b) Sigmoid
  1. 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
  1. 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
  1. Which optimizer is commonly used in deep learning?
  • a) Linear Regression
  • b) Adam
  • c) KNN
  • d) SVM
    Answer: b) Adam
  1. 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
  1. What does dropout help prevent in deep learning models?
  • a) Slow convergence
  • b) Overfitting
  • c) Vanishing gradient
  • d) Underfitting
    Answer: b) Overfitting
  1. What does max_depth control 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
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments