Python Programming
MCQS:
MCQs :
1. Python was created by:
a) James Gosling
b) Guido van Rossum
c) Dennis Ritchie
d) Bjarne Stroustrup
2. Python was released in:
a) 1990
b) 1991
c) 1995
d) 2000
3. Python is:
a) High-level and compiled
b) Low-level and interpreted
c) High-level and interpreted
d) Low-level and compiled
4. Which of the following is not a feature of Python?
a) Easy to learn
b) Cross-platform
c) Low-level
d) Free and open source
5. Python is used in:
a) Web development
b) Data science
c) Scripting
d) All of the above
6. Which Python editor is not mentioned in the document?
a) Jupyter
b) Spyder
c) VS Code
d) PyCharm
7. What does the import statement do in Python?
a) Defines a variable
b) Declares a function
c) Imports a library
d) Assigns values to a variable
8. What is the output of the following code: print(“National Animal-Tiger”)?
a) National Animal Tiger
b) National Animal-Tiger
c) “National Animal-Tiger”
d) None of the above
9. The input() function returns values as:
a) Integer
b) Float
c) String
d) Boolean
10. The explicit conversion of a value from one data type to another is called:
a) Data binding
b) Type casting
c) Overloading
d) Data parsing
11. Which of the following is an immutable data type?
a) List
b) Set
c) Tuple
d) Dictionary
12. The correct way to define a list in Python is:
a) {1, 2, 3}
b) [1, 2, 3]
c) (1, 2, 3)
d) 1, 2, 3
13. Which operator is used to compare values in Python?
a) =
b) ==
c) !=
d) Both b and c
14. In Python, a tuple:
a) Is mutable
b) Is immutable
c) Allows duplicates
d) Both b and c
15. The correct syntax to start a “for” loop in Python is:
a) for x in range(5)
b) for x in (5):
c) for x to 5
d) for x range(5)
16. The is operator checks:
a) Value equality
b) Identity equality
c) String equality
d) List equality
17. The function float() converts data into:
a) Boolean
b) Integer
c) Float
d) String
18. In Python, indentation is used to:
a) Separate blocks of code
b) Declare a variable
c) Import a library
d) Assign values to a variable
19. Which of the following is a Python keyword?
a) for
b) if
c) while
d) All of the above
20. What does the “pass” keyword do in Python?
a) Terminates the loop
b) Skips the current iteration
c) Does nothing
d) Exits the function
21. A Pandas DataFrame is:
a) A one-dimensional array
b) A two-dimensional labeled data structure
c) A dictionary
d) A scalar value
22. Which of these is not a Python literal?
a) Boolean
b) Numeric
c) Identifier
d) String
23. To define a dictionary in Python, you use:
a) {key: value}
b) [key: value]
c) (key: value)
d) key, value
24. A Python set:
a) Is unordered
b) Does not allow duplicates
c) Allows mutable elements
d) Both a and b
25. CSV stands for:
a) Common Spreadsheet Values
b) Comma Separated Values
c) Common Script Values
d) Comma Spaced Values
26. A function in the math library to calculate the square root is:
a) math.pow()
b) math.sqrt()
c) math.abs()
d) math.exp()
27. The correct way to install a Python library like Numpy is:
a) install numpy
b) python install numpy
c) pip install numpy
d) conda numpy
28. The method to add a new column to a Pandas DataFrame is:
a) DataFrame.append()
b) DataFrame.add()
c) DataFrame.insert()
d) DataFrame.loc[]
29. Which function is used to check for missing values in a Pandas DataFrame?
a) isnull()
b) dropna()
c) fillna()
d) empty()
30. The Python KNeighborsClassifier is used for:
a) Clustering
b) Regression
c) Classification
d) Dimensionality reduction
31. In Python, X_train and y_train represent:
a) Test data
b) Training data
c) Validation data
d) Output variables
32. The default delimiter for reading CSV files in Pandas is:
a) Tab
b) Space
c) Comma
d) Semicolon
33. The most common ratio for splitting data into training and testing sets is:
a) 50:50
b) 80:20
c) 90:10
d) 70:30
34. What does random_state = 1 ensure in train_test_split?
a) Randomness in the split
b) Consistency of the split
c) Random shuffling
d) Variable selection
35. Which of the following is not a supervised learning algorithm?
a) K-Nearest Neighbors
b) Decision Trees
c) K-Means
d) Naive Bayes
36. To read a CSV file in Pandas, you use:
a) pandas.open()
b) pandas.load()
c) pandas.read()
d) pandas.read_csv()
37. In Python, an identifier cannot:
a) Start with a letter
b) Start with an underscore
c) Contain special characters
d) Be a keyword
38. Which of the following data types is mutable in Python?
a) List
b) Tuple
c) String
d) Integer
39. Which of the following operators is used for bitwise AND in Python?
a) &&
b) ||
c) &
d) !
40. A Series in Pandas is:
a) One-dimensional
b) Two-dimensional
c) Three-dimensional
d) Immutable
41. To delete rows in a DataFrame, you use:
a) drop()
b) remove()
c) delete()
d) clear()
42. Which of the following libraries is not used in Python for AI and data science?
a) Scikit-learn
b) NumPy
c) TensorFlow
d) Bootstrap
43. A DataFrame can be created using:
a) Lists
b) Dictionaries
c) Numpy ndarrays
d) All of the above
44. In Python, # is used to:
a) Denote comments
b) Denote variables
c) Indent blocks
d) Import libraries
45. Which operator is used to check membership in Python?
a) in
b) ==
c) is
d) &&
46. Which method in Pandas adds a row to a DataFrame?
a) append()
b) add()
c) loc[]
d) insert()
47. What function is used to calculate accuracy in Scikit-learn?
a) metrics.confusion_matrix()
b) metrics.recall()
c) metrics.accuracy_score()
d) metrics.precision()
48. Which statement is true for Python strings?
a) They are mutable
b) They are immutable
c) They can contain numbers
d) Both b and c
49. A DataFrame’s index can be reset using:
a) DataFrame.reset()
b) DataFrame.reset_index()
c) DataFrame.clear_index()
d) DataFrame.loc[]
50. Which keyword is used to define a function in Python?
a) define
b) function
c) def
d) fun