NPTEL – Python for Data Science
Question & Answer Revision – 30 Practice Questions
1. Which operator is NOT normally applicable between two strings in Python?
A) +
B) *
C) -
D) None of these
Correct Answer: C) -
2. Which function returns the list of attributes and methods of an object?
A) abs()
B) dir()
C) bin()
D) type()
Correct Answer: B) dir()
3. If X = 3 and Y = 6, which statement swaps their values?
A) X=Y; Y=X
B) X,Y = Y,X
C) Y=X
D) X=Y
Correct Answer: B) X,Y = Y,X
4. What is the result of 7 // 2?
A) 2
B) 3
C) 3.5
D) 4
Correct Answer: B) 3
5. Which of the following is immutable?
A) List
B) Set
C) Tuple
D) Dictionary
Correct Answer: C) Tuple
6. What does s[-1] return for a Python string s?
A) First character
B) Last character
C) Length
D) Error
Correct Answer: B) Last character
7. What is the main purpose of pandas?
A) Data manipulation and analysis
B) Game development
C) Operating system design
D) Web hosting
Correct Answer: A) Data manipulation and analysis
8. Which NumPy attribute gives the number of dimensions of an array?
A) size
B) ndim
C) shape()
D) length
Correct Answer: B) ndim
9. Which is a valid list comprehension?
A) [x*x for x in range(4)]
B) [x*x; range(4)]
C) list[x*x]
D) {x*x range(4)}
Correct Answer: A) [x*x for x in range(4)]
10. Which operation finds common elements of two sets?
A) Union
B) Intersection
C) Difference
D) Append
Correct Answer: B) Intersection
11. Which pandas function reads a CSV file?
A) pd.read_csv()
B) pd.open_csv()
C) [Link]()
D) pd.load_csv()
Correct Answer: A) pd.read_csv()
12. Which argument can specify a CSV column as the DataFrame index while
reading?
A) index_col
B) column_index
C) key_col
D) set_index
Correct Answer: A) index_col
13. Which pandas method is used to fill missing values?
A) dropna()
B) fillna()
C) nullfill()
D) replace_null()
Correct Answer: B) fillna()
14. Which plot is mainly used to show the distribution of numerical data?
A) Histogram
B) Pie chart
C) Flowchart
D) Network graph
Correct Answer: A) Histogram
15. A box plot is useful for showing:
A) Five-number summary and outliers
B) Only the mean
C) Only text
D) Source code
Correct Answer: A) Five-number summary and outliers
16. What is a scatter plot mainly used to study?
A) Relationship between two numerical variables
B) File size
C) String length
D) Package installation
Correct Answer: A) Relationship between two numerical variables
17. What is the range of a correlation coefficient?
A) 0 to 1
B) -1 to +1
C) -100 to +100
D) 1 to 10
Correct Answer: B) -1 to +1
18. Adding the same constant to every value of a variable generally does what to
its correlation with another variable?
A) Leaves it unchanged
B) Makes it zero
C) Makes it one
D) Reverses its sign
Correct Answer: A) Leaves it unchanged
19. Categorical variables can commonly be converted into numerical form using:
A) Dummy/one-hot variables
B) Histogram
C) Box plot
D) Residual plot
Correct Answer: A) Dummy/one-hot variables
20. Logistic regression is commonly used for:
A) Classification
B) Image compression
C) File copying
D) Sorting strings
Correct Answer: A) Classification
21. The output of the logistic (sigmoid) function lies between:
A) -∞ and +∞
B) 0 and 1
C) -1 and 1
D) 1 and 100
Correct Answer: B) 0 and 1
22. Which loss is commonly associated with logistic regression?
A) Log loss
B) Hinge only
C) Euclidean distance only
D) None
Correct Answer: A) Log loss
23. In regression, a residual is generally:
A) Actual − predicted
B) Actual + predicted
C) Actual × predicted
D) Predicted ÷ actual
Correct Answer: A) Actual − predicted
24. RMSE stands for:
A) Root Mean Squared Error
B) Random Mean Statistical Estimate
C) Relative Model Score Error
D) Root Median Standard Estimate
Correct Answer: A) Root Mean Squared Error
25. Why is train/test split used?
A) To evaluate performance on unseen data
B) To delete data
C) To rename columns
D) To create only plots
Correct Answer: A) To evaluate performance on unseen data
26. In KNN, why is feature scaling often important?
A) Distance calculations depend on feature magnitudes
B) It deletes missing values
C) It creates labels
D) It converts text to images
Correct Answer: A) Distance calculations depend on feature magnitudes
27. Which statement correctly describes supervised learning?
A) Model learns from labelled data
B) Model never uses data
C) Only images can be used
D) No target variable is needed
Correct Answer: A) Model learns from labelled data
28. Which of these is an example of unsupervised learning?
A) Clustering
B) Linear regression with known targets
C) Logistic regression with labels
D) Classification with labelled data
Correct Answer: A) Clustering
29. If 3 out of 6 marbles are red, what is the probability of drawing a red marble?
A) 1/3
B) 1/2
C) 2/3
D) 5/6
Correct Answer: B) 1/2
30. In a single-elimination tournament with 128 players, how many games are
required to determine one winner?
A) 64
B) 127
C) 128
D) 256
Correct Answer: B) 127