Viva Questions For Python Lab
Viva Questions For Python Lab
1.What is Python?
Python is a high-level, interpreted, general-purpose programming language. Being a
general-purpose language, it can be used to build almost any type of application with
the right tools/libraries.
2. What are the applications of Python?
Web and Internet Development
Games
Scientific and computational applications
Language development
Image processing and graphic design applications
3. What is the difference between a list and a tuple?
List:
Lists are enclosed with in square []
Lists are mutable, that is their elements and size can be changed.
Lists are slower than tuples.
Example: [‘A’, 1, ‘i’]
Tuple:
Tuples are enclosed in parentheses ()
Tuples are immutable i.e cannot be edited.
Tuples are faster than lists.
Tuples must be used when the order of the elements of a sequence matters.
Example: (‘Twenty’, 20, ‘XX’)
6.Define Lambda function?
A lambda function is a small anonymous function. A lambda function can takes any
no of arguments but can have only one expression.
.eg: x= lambda a:a+10
print(x)
5. What is the difference between del(), clear(), remove(), and pop()?
del(): deletes the with respect to the position of the value. It does not return which
value is deleted. It also changes the index towards the right by decreasing one
value. It can also be used to delete the entire data structure.
clear(): clears the list.
remove(): it deletes with respect to the value hence can be used if you know which
particular value to delete.
pop(): by default removes the last element and also returns back which value is
deleted. It is used extensively when we would want to create referencing. In sense,
we can store this deleted return value in a variable and use in future
6. What is the difference between pass, continue and break?
Pass: It is used when you need some block of code syntactically, but you want to
skip its execution. This is basically a null operation. Nothing happens when this is
executed.
Continue: It allows to skip some part of a loop when some specific condition is met,
and the control is transferred to the beginning of the loop. The loop does not
terminate but continues with the next iteration.
Break: It allows the loop to terminate when some condition is met, and the control of
the program flows to the statement immediately after the body of the loop. If the
break statement is inside a nested loop (the loop inside another loop), then the break
statement will terminate the innermost loop.
7. What is Regex? List some of the important Regex functions in Python.
Regular Expression or RegEx is a sequence of characters that are used to create
search patterns. In Python, the following RegEx functions are mostly used:
Reduce function applies the same operation to items of a sequence. It uses the
result of operations as the first param of the next operation. It returns an item and not
a list.
Filter function filters an item out of a sequence. It is used to filter the given iterable
(list, sets, tuple) with the help of another function passed as an argument to test all
the elements to be true or false. Its output is a filtered list.
NUMPY:
Answer:
It takes only a few lines of code to achieve complex computations using NumPy
Answer:
Python lists support storing heterogeneous data types whereas NumPy arrays can
store datatypes of one nature itself. NumPy provides extra functional capabilities that
make operating on its arrays easier which makes NumPy array advantageous in
comparison to Python lists as those functions cannot be operated on heterogeneous
data.
sorting types:-
sort - np.sort()
Answer:
· np.mean() method calculates the arithmetic mean and provides additional options
for input and results. For example, it has the option to specify what data types have
to be taken, where the result has to be placed etc.
Answer:
· When the size of ndarrays is changed, it results in a new array and the original
array is deleted.
· The ndarrays are bound to store homogeneous data.
Answer:
2. From ndarray class directly: There are two modes of creating an array using
__new__: If buffer is None, then only shape, dtype, and order are used. If buffer is
an object exposing the buffer interface, then all keywords are interpreted.
Answer:
Vectorization takes one elemental operation and applies to all the elements in that
array for you. Underneath, the implementatiosn are in C, hence providing substantial
speed gains. NumPy already has a large number of operations vectorized, for eg: all
arithmetic operators, logical operators, etc. Numpy also provides a way for you to
vectorize your function.
PANDAS:
1) What is pandas in python?
Pandas is an open source python package that is most widely used for data
science/data analysis and machine learning tasks. It is built on top of another
package named Numpy which provides support for multi-dimensional arrays.
2) Mention the different types of Data Structures in Pandas?
1.Series
2.DataFrames
A Series is a one-dimensional data structure in pandas, whereas the DataFrame is
the two-dimensional data structure in pandas.
3) Define Reindexing in Pandas?
Reindexing is used to change the index of the rows and columns of the
DataFrame. We can reindex the single or multiple rows by using the reindex()
method. Default values in the new index are assigned NaN if it is not present
in the DataFrame.
The pandas library has a number of features, some of which are shown here.
Memory Efficient
Time Series
Reshaping
Data Alignment
Merge and join
To make a Pandas data frame that is fully empty, perform the following:
import pandas as pd
MyEmptydf ()= pd.DataFrame
This will result in a data frame that has no columns or rows.
We do the following to construct an empty dataframe with three empty columns
(columns A, B, and C): df= pd.DataFrame(columns=['A', 'B', 'C'])
The loc() function is label based data selecting method which means that we
have to pass the name of the row or column which we want to select. This
method includes the last element of the range passed in it, unlike iloc(). loc()
can accept the Boolean data unlike iloc().
Output:
10 100
11 110
12 120
MATPLOTLIB:
1.what are magic functions in matplotlib?
ans:%matplotlib notebook & %matplotlib inline
2. What is a Pairplot?
Ans:A Pair plot shows the relationships for a pair of columns of the data.
It creates a matrix of axes where the diagonals show the distribution of each variable
with itself.
3.what is use of markers in matplotplib?
ans:it is module which can be used in both scatter and plot.
It consist of facecolor,edgecolor,edgewidth etc..(circle,point,pixel,triangle-up,triangle-
down etc..,)
4.what is the module to import 3d matplotlib?
ans:from mpl_toolkits import mplot3d
5.what is legend and use of it?
ans:legend is the element to describe the graph and
the location can be given to place the legend ex:upperleft,upper roght,lower
left,lower right
6.what is cmap?
ans:cmap stands for colormap and it's a colormap instance or registered colormap
name
7.what is the use of magic function?
ans:Magic methods are most frequently used to define overloaded behaviours of
predefined operators in Python
8.what is the use of figure function?
ans:The figure() function in pyplot module of matplotlib library is used to create a
new figure
9.what are the arguments to be given in the linspace function?
ans: (range,collection of points).
10.what is the property of alpha?
ans:it used for color value transparancy.
11.what are the methods of visulaiztion tools in maytplotlib?
ans:plot(linear polt),scatterplot,contour polt,histogram,etc..