MCQs on Python Libraries and Frameworks | Python programming

1. NumPy and Pandas (for data analysis)

  1. Which of the following is used to create a NumPy array in Python?
    • a) numpy.array()
    • b) numpy.ndarray()
    • c) pandas.DataFrame()
    • d) pandas.Series()
  2. What is the output of numpy.zeros((2,3))?
    • a) A 2×3 matrix filled with ones.
    • b) A 2×3 matrix filled with zeros.
    • c) A 2×3 matrix filled with random numbers.
    • d) A 3×2 matrix filled with zeros.
  3. Which of the following is used to create a DataFrame in Pandas?
    • a) pandas.DataFrame()
    • b) numpy.array()
    • c) numpy.matrix()
    • d) pandas.Series()
  4. What is the default axis for the sum() function in Pandas?
    • a) 0 (columns)
    • b) 1 (rows)
    • c) None
    • d) 2 (diagonal)
  5. Which Pandas function is used to read a CSV file?
    • a) read_csv()
    • b) load_csv()
    • c) import_csv()
    • d) read()
  6. Which of the following functions in Pandas is used to check the data type of a column?
    • a) df.dtype()
    • b) df.dtypes()
    • c) df.data()
    • d) df.checktype()
  7. What does the pandas.concat() function do?
    • a) Merges two DataFrames by column.
    • b) Merges two DataFrames by row.
    • c) Creates a new DataFrame from individual rows.
    • d) Sorts a DataFrame by column.

2. Matplotlib (for data visualization)

  1. Which function in Matplotlib is used to display a plot?
    • a) show_plot()
    • b) plot()
    • c) display()
    • d) show()
  2. What does plt.plot([1,2,3], [4,5,6]) do in Matplotlib?
    • a) Plots a graph with x-values 1, 2, 3 and y-values 4, 5, 6.
    • b) Plots a pie chart with values 1, 2, 3.
    • c) Plots a line chart of random numbers.
    • d) Creates a bar chart with x and y values.
  3. Which of the following is used to set the title of a Matplotlib plot?
    • a) plt.title()
    • b) plt.name()
    • c) plt.label()
    • d) plt.set_title()
  4. How do you add a legend to a Matplotlib plot?
    • a) plt.legend()
    • b) plt.add_legend()
    • c) plt.legendize()
    • d) plt.add_title()
  5. Which of the following is used to plot a bar chart in Matplotlib?
    • a) plt.hist()
    • b) plt.plot()
    • c) plt.bar()
    • d) plt.scatter()
  6. What is the purpose of plt.xlabel() in Matplotlib?
    • a) To set the title of the plot.
    • b) To set the label of the x-axis.
    • c) To set the label of the y-axis.
    • d) To display the grid on the plot.

3. Requests (for HTTP requests)

  1. Which of the following methods is used to send a GET request in the requests library?
    • a) requests.get()
    • b) requests.request()
    • c) requests.send()
    • d) requests.get_request()
  2. What is the purpose of the requests.post() method in the Requests library?
    • a) To send a GET request.
    • b) To send a POST request.
    • c) To fetch the status code of a URL.
    • d) To send a PUT request.
  3. How do you pass parameters in a GET request using the requests library?
    • a) Using params argument in requests.get().
    • b) Using data argument in requests.get().
    • c) Using body argument in requests.get().
    • d) Using headers argument in requests.get().
  4. Which of the following methods in requests is used to check the status code of a response?
    • a) response.status()
    • b) response.check()
    • c) response.status_code()
    • d) response.get_status()
  5. How can you send JSON data in a POST request using the requests library?
    • a) requests.post(url, data=json_data)
    • b) requests.post(url, json=json_data)
    • c) requests.send(url, json=json_data)
    • d) requests.post(url, body=json_data)
  6. Which of the following is used to send authentication credentials in a GET request using the Requests library?
    • a) auth=(username, password)
    • b) headers={'Authorization': 'Bearer token'}
    • c) cookies={'session': 'value'}
    • d) params={'auth': 'username:password'}

4. Flask and Django (for web development)

  1. Which of the following is used to define routes in Flask?
    • a) @flask.route()
    • b) @app.route()
    • c) @app.connect()
    • d) @flask.connect()
  2. What does the Flask class in Flask do?
    • a) Handles HTTP requests and responses.
    • b) Manages the database connection.
    • c) Sets up the configuration for the app.
    • d) All of the above.
  3. Which of the following is the default port number for Flask development server?
    • a) 8080
    • b) 5000
    • c) 8000
    • d) 4000
  4. In Django, which file is used to configure URLs for the application?
    • a) urls.py
    • b) settings.py
    • c) app.py
    • d) views.py
  5. What is the default database used by Django?
    • a) SQLite
    • b) PostgreSQL
    • c) MySQL
    • d) MongoDB
  6. In Django, which of the following command is used to create a new application?
    • a) django-admin startproject
    • b) django-admin startapp
    • c) python manage.py startapp
    • d) python manage.py newapp
  7. Which of the following is used for handling static files in Django?
    • a) django.static()
    • b) django.urls()
    • c) django.contrib.staticfiles
    • d) django.staticfiles()

5. TensorFlow and PyTorch (for machine learning)

  1. What is TensorFlow used for?
    • a) Web development.
    • b) Machine learning and deep learning.
    • c) Data visualization.
    • d) Database management.
  2. Which of the following is a key feature of PyTorch?
    • a) Static computation graph.
    • b) Dynamic computation graph.
    • c) Data analysis.
    • d) Web development.
  3. Which function in TensorFlow is used to create a constant tensor?
    • a) tf.constant()
    • b) tf.variable()
    • c) tf.create()
    • d) tf.data()
  4. In PyTorch, which of the following is used to define a neural network layer?
    • a) torch.nn.layer()
    • b) torch.layers()
    • c) torch.nn.Module()
    • d) torch.tensor()

Answers (Tabular Form)

QnoAnswer
1a) numpy.array()
2b) A 2×3 matrix filled with zeros.
3a) pandas.DataFrame()
4a) 0 (columns)
5a) read_csv()
6b) df.dtypes()
7b) Merges two DataFrames by row.
8d) show()
9a) Plots a graph with x-values 1, 2, 3 and y-values 4, 5, 6.
10a) plt.title()
11a) plt.legend()
12c) plt.bar()
13b) To set the label of the x-axis.
14a) requests.get()
15b) To send a POST request.
16a) Using params argument in requests.get().
17c) response.status_code()
18b) requests.post(url, json=json_data)
19a) auth=(username, password)
20b) @app.route()
21a) Handles HTTP requests and responses.
22b) 5000
23a) urls.py
24a) SQLite
25b) django-admin startapp
26c) django.contrib.staticfiles
27b) Machine learning and deep learning.
28b) Dynamic computation graph.
29a) tf.constant()
30c) torch.nn.Module()

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top