0% found this document useful (0 votes)
6 views13 pages

Python QB

The document outlines various questions and topics related to Python programming, covering fundamental concepts, data structures, libraries like NumPy and Pandas, and visualization with Matplotlib. It includes questions categorized by difficulty (2 marks, 6 marks, and 10 marks) that address key programming concepts, data manipulation, and analysis techniques. The document serves as a comprehensive guide for learners to understand and apply Python in different contexts such as data science and machine learning.

Uploaded by

Snicky Snoops
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views13 pages

Python QB

The document outlines various questions and topics related to Python programming, covering fundamental concepts, data structures, libraries like NumPy and Pandas, and visualization with Matplotlib. It includes questions categorized by difficulty (2 marks, 6 marks, and 10 marks) that address key programming concepts, data manipulation, and analysis techniques. The document serves as a comprehensive guide for learners to understand and apply Python in different contexts such as data science and machine learning.

Uploaded by

Snicky Snoops
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT-1

Two Marks Questions


1. What is a variable in Python?
a. Explain the concept of a variable and give an example.
2. What are the basic data types in Python?
a. List at least four basic data types and provide a brief
description of each.
3. What is a Boolean value?
a. Define Boolean values and provide an example of a Boolean
expression.
4. How do you create a list in Python?
a. Write a simple code snippet to create a list of five integers.
5. What is a tuple?
a. Explain what a tuple is and how it differs from a list.
6. What is a dictionary in Python?
a. Define a dictionary and provide an example of how to create
one.
7. What is a lambda function?
a. Describe a lambda function and provide a simple example.
8. What is the purpose of decorators in Python?
a. Briefly explain what decorators are and their use case.
9. What is an iterator?
a. Define an iterator and explain how it differs from a
generator.
10. What are Python sets?
a. Describe what a set is and provide an example of how to
create one.
Six Marks Questions
1. Explain the difference between mutable and immutable types in
Python.
a. Provide examples of each type and discuss their implications
in programming.
2. How do you perform basic arithmetic operations in Python?
a. Write a code snippet demonstrating addition, subtraction,
multiplication, and division.
3. Describe how to use list comprehensions in Python.
a. Provide an example of a list comprehension that generates a
list of squares of numbers from 1 to 10.
4. What are the key differences between lists and tuples?
a. Discuss at least three differences, including mutability and
performance.
5. Explain how to define and use a function in Python.
a. Provide an example of a simple function that takes
parameters and returns a value.
6. How do you handle exceptions in Python?
a. Describe the try-except block and give an example of how it
can be used.
Ten Marks Questions
1. Explain the concept of scope in Python.
a. Discuss local and global variables with examples, and explain
how scope affects variable accessibility.
2. Discuss the various ways to iterate over a list in Python.
a. Provide examples using a for loop, while loop, and list
comprehensions.
3. What are the different methods available for dictionaries in
Python?
a. Describe at least five dictionary methods with examples.
4. Explain the concept of generators in Python.
a. Discuss how generators work, their benefits, and provide an
example of a simple generator function.
5. Describe the use of the map(), filter(), and reduce() functions in
Python.
a. Provide examples for each function and explain their
purposes.
6. How do decorators work in Python?
a. Explain the syntax and provide an example of a decorator
that logs function calls.
7. What is the difference between shallow copy and deep copy?
a. Discuss how to create both types of copies in Python and
provide examples.
8. Explain the use of the with statement in Python.
a. Describe how it is used for resource management and
provide an example with file handling.
9. Discuss the importance of the __init__ method in Python classes.
a. Explain its role in object-oriented programming and provide
an example of a class with an __init__ method.
10. What are the differences between Python 2 and Python 3?
a. Discuss at least five differences, including print statements,
integer division, and Unicode support.
2 Marks Questions
What is NumPy?
Define NumPy and its primary purpose in Python.
How to install NumPy?
Describe the installation process of NumPy on different operating systems.
What is an ndarray?
Explain what an ndarray is in NumPy.
How do you create a NumPy array?
Provide a simple example of creating a NumPy array.
What is the purpose of the [Link]() function?
Describe the function and provide an example.
How do you perform element-wise addition in NumPy?
Explain with a brief example.
What is the [Link]() function?
Define the function and its use case.
Explain the difference between [Link]() and [Link]().
Provide a concise explanation.
What is the Seaborn library used for?
Describe the primary use of Seaborn in data visualization.
What is a histogram?
Define a histogram and its purpose in data analysis.
6 Marks Questions
Discuss the advantages of using NumPy over Python lists.
Elaborate on at least three advantages.
Explain how to perform basic statistical operations using NumPy.
Provide examples for mean, median, and standard deviation.
What are broadcasting rules in NumPy?
Explain broadcasting with an example.
Describe how to generate random numbers from a normal distribution using
NumPy.
Provide a code example.
How can you visualize data distributions using Seaborn?
Discuss at least two types of plots that can be used.
Explain the use of the numpy. [Link]() function.
Describe the function and provide an example of its application.
10 Marks Questions
Provide a comprehensive overview of different distributions available in NumPy.
Discuss normal, binomial, Poisson, logistic, chi-square, and Rayleigh distributions.
Demonstrate how to create and visualize a random sample from a normal
distribution using NumPy and Seaborn.
Include code snippets and explanations.
Explain the concept of random permutations and its applications in statistical
sampling.
Discuss with examples.
How can you perform linear algebra operations using NumPy?
Provide examples of matrix multiplication and finding eigenvalues.
Discuss the importance of NumPy in the context of machine learning.
Explain how NumPy supports various machine learning libraries.
Create a comparative analysis of the Poisson and binomial distributions.
Discuss their characteristics, applications, and differences.
UNIT III
2-Mark Questions
1. What is the purpose of the [Link]() method?
2. Name the three correlation methods available in Pandas.
3. What does the min_periods parameter do in the corr() method?
4. How does Pandas handle missing values when computing
correlations?
5. What is the default correlation method used by [Link]()?
6. What type of data does the numeric_only parameter
in [Link]() filter?
7. Explain the significance of the diagonal values in a correlation
matrix.
8. What is the function of the method parameter
in [Link]()?
9. How can you compute the correlation between a Series and a
DataFrame?
10. What is the output of the corr() method when applied to a
DataFrame with only one column?
6-Mark Questions
1. Describe the process of installing Pandas and SciPy in a Python
environment.
2. Explain how to create a Pandas DataFrame and compute the
correlation matrix for its columns. Provide a code example.
3. Discuss the differences between Pearson, Kendall, and Spearman
correlation coefficients. When would you use each?
4. Illustrate how to plot correlations using Pandas. What functions
would you use?
5. Define sparse data in the context of Pandas. How can you handle
sparse data using Pandas?
6. What are optimizers in SciPy? Provide an example of an
optimization problem that can be solved using SciPy.
10-Mark Questions
1. Discuss the concept of interpolation in data analysis. Provide
examples of different interpolation methods available in Pandas.
2. Explain how to work with spatial data in Pandas. What are the
common libraries used alongside Pandas for spatial data analysis?
3. Create a detailed example that demonstrates how to use Pandas for
time series analysis, including correlation and plotting.
4. Describe the steps to perform data normalization using Pandas and
explain its importance in data analysis.
5. Explain the concept of optimizers in SciPy with a focus on
the minimize function. Provide a code example that demonstrates
its use.
6. Discuss the importance of data alignment in Pandas when
performing operations like correlation. How does Pandas ensure
data alignment?
UNIT IV
2-Mark Questions
What is Matplotlib?
Matplotlib is a Python library used for creating static, animated, and
interactive visualizations.
Who originally developed Matplotlib?
Matplotlib was originally developed by John D. Hunter in 2003.
What command is used to install Matplotlib using pip?
The command is pip install matplotlib.
What is the primary purpose of Matplotlib?
The primary purpose of Matplotlib is to provide tools for graphical data
representation.
Can Matplotlib be used with Jupyter Notebooks?
Yes, Matplotlib integrates seamlessly with Jupyter Notebooks.
What type of plots can Matplotlib create?
Matplotlib can create line plots, scatter plots, bar plots, histograms, and
pie charts.
What is a figure in Matplotlib?
A figure is the top-level container that holds all the elements of a plot.
How do you check the installed version of Matplotlib?
Use the command print(matplotlib.__version__).
What is the significance of markers in Matplotlib?
Markers are used to denote points in a plot, enhancing data
visualization.
What is the function of the grid in a plot?
Grids improve the readability of plots by providing reference lines.
6-Mark Questions
1. Explain how to install Matplotlib using Anaconda.
To install Matplotlib using Anaconda, open the Anaconda Prompt
and run the command conda install matplotlib. It is recommended
to create a new environment for installation.
2. Describe the process of creating a simple line plot in Matplotlib.
To create a line plot, first import Matplotlib, then define your data
points. Use the plot() function to create the plot and show() to
display it.
3. Discuss the customization options available for markers in
Matplotlib.
Markers can be customized in terms of shape, size, and color using
parameters like marker, markersize, and color in
the plot() function.
4. What are subplots, and how do you create them in Matplotlib?
Subplots allow multiple plots to be displayed in a single figure.
Use [Link](nrows, ncols, index) to create subplots,
where nrows and ncols define the grid layout.
5. Explain the difference between bar charts and histograms in
Matplotlib.
Bar charts represent categorical data with rectangular bars, while
histograms represent the distribution of numerical data by dividing
it into bins.
6. How do you add labels and titles to a plot in Matplotlib?
Use [Link]('X-axis label'), [Link]('Y-axis label'),
and [Link]('Plot Title') to add labels and titles to your plot.
10-Mark Questions
1. Provide a detailed guide on installing Matplotlib using pip and
conda.
Explain the steps for both methods, including commands,
verification of installation, and troubleshooting common issues.
2. Discuss the various types of plots available in Matplotlib and their
applications.
Elaborate on line plots, scatter plots, bar charts, histograms, and pie
charts, including when to use each type for effective data
visualization.
3. Explain the process of creating and customizing a scatter plot in
Matplotlib.
Detail how to create a scatter plot, including setting colors and sizes
based on data attributes, and how to enhance the plot with titles and
labels.
4. Describe how to implement grids in plots and their importance.
Discuss how to add grids using [Link](), the types of grids
available, and how they improve plot readability.
5. Illustrate the concept of subplots with an example.
Provide a code example that demonstrates creating multiple
subplots in a single figure, including layout customization.
6. Explain the process of creating a pie chart in Matplotlib.
Detail how to create a pie chart, including data preparation,
customization options like colors and labels, and how to display the
chart.
UNIT-V
2-Mark Questions
1. What is a list in Python?
A list is a collection of items in a particular order, enclosed in
square brackets [].
2. How do you create an empty list in Python?
You can create an empty list using empty square brackets [].
3. What is the purpose of list comprehension in Python?
List comprehension provides a concise way to create a new list
based on an existing list.
4. How do you access an element in a list using its index?
You can access an element using its index, for example, my_list to
get the first element.
5. What is the purpose of slicing in Python lists?
Slicing allows you to extract a subset of elements from a list based
on their indices.
6. How do you append an element to a list in Python?
You can use the append() method to add an element to the end of a
list.
7. What is the purpose of the range() function in Python?
The range() function generates a sequence of numbers within a
specified range.
8. How do you remove an element from a list in Python?
You can use the remove() method to remove the first occurrence of
a specified element.
9. What is the purpose of the openpyxl library in Python?
The openpyxl library allows you to read and write Excel files in
Python.
10. What is the purpose of the pandas library in Python?
The pandas library provides high-performance, easy-to-use data
structures and data analysis tools for working with structured
(tabular, multidimensional, potentially heterogeneous) and time
series data.
6-Mark Questions
1. Explain the syntax and usage of list comprehension in Python.
List comprehension allows you to create a new list by applying an
expression to each element of an existing list. The syntax
is [expression for item in iterable if condition].
2. Describe the concept of slicing in Python lists.
Slicing allows you to extract a subset of elements from a list based
on their indices. The syntax is my_list[start:stop:step],
where start is the inclusive lower bound, stop is the exclusive upper
bound, and step is the optional step size.
3. Explain how to read data from an Excel file using
the openpyxl library.
To read data from an Excel file using openpyxl, you need to load
the workbook, select the desired worksheet, and then access the
cell values.
4. Discuss the use of Python in Internet of Things (IoT) applications.
Python is widely used in IoT applications due to its simplicity,
readability, and extensive library support. It can be used for device
communication, data processing, and cloud integration.
5. Explain how Python is used in Machine Learning.
Python is a popular language for Machine Learning due to its ease
of use, powerful libraries like scikit-learn and TensorFlow, and its
ability to handle large datasets efficiently.
6. Describe the role of Python in Data Science.
Python is a versatile language for Data Science, with libraries
like NumPy, Pandas, and Matplotlib that enable data
manipulation, analysis, and visualization. It is widely used for
tasks such as data cleaning, exploratory data analysis, and building
predictive models.
10-Mark Questions
1. Discuss the various data structures available in Python and their
use cases.
Python offers several built-in data structures, including lists,
tuples, sets, and dictionaries. Explain the characteristics of each
data structure, their advantages, and when to use them based on
specific requirements.
2. Demonstrate the power of list comprehension by providing
examples of its usage in different scenarios.
Provide multiple examples showcasing the versatility of list
comprehension, such as creating a list of squares, filtering
elements based on conditions, and transforming elements using
expressions. Highlight how list comprehension can make code
more concise and readable.
3. Explain the process of reading data from multiple Excel sheets and
performing data analysis using Python.
Demonstrate how to use the openpyxl library to read data from
multiple Excel sheets, handle missing values, and perform basic
data analysis tasks like calculating summary statistics and creating
visualizations.
4. Discuss the role of Python in the development of IoT applications,
including device communication, data processing, and cloud
integration.
Provide a comprehensive overview of how Python is used in IoT
applications, including examples of device communication
protocols like MQTT, data processing techniques for sensor data,
and integration with cloud platforms for data storage and analysis.
5. Explain how Python is used in various stages of the Machine
Learning workflow, from data preprocessing to model deployment.
Describe how Python is used in different stages of the Machine
Learning workflow, such as data preprocessing using libraries
like NumPy and Pandas, model training and evaluation
using scikit-learn, and model deployment using frameworks
like Flask or Django.
6. Showcase a case study demonstrating the application of Python in
a real-world Data Science project.
Present a case study that demonstrates the use of Python in a Data
Science project, such as predicting customer churn or analyzing
social media sentiment. Explain the data collection process, data
preprocessing techniques, feature engineering, model selection,
and evaluation metrics used in the project.

You might also like