Q1. For a multi-channel input feature map, we apply Max-pooling independently on each channel and then concatenate the results along the channel axis?
True
False
Answer: 1 Explanation: Max-pooling operation is applied independently on each channel and then the results are concatenated along the channel axis to form the final output. Refer to this beautiful explanation by Andrew Ng to understand more.
Q2. A fully convolutional network can take as input the image of any size?
True
False
Answer: 1 Explanation: Because a fully convolutional network doesnot contain any fully connected or Dense layer, this can take as input the image of any size.
Q3. In R-CNN, the bounding box loss is only calculated for positive samples (samples that contains classes present in the dataset)?
True
False
Answer: 1 Explanation: In R-CNN, the bounding box loss is only calculated for positive samples (samples that contains classes present in the dataset) as it makes no sense to fine-tune a bounding box that doesn’t contain object.
Q4. In the VGG16 model, we have all the Conv layers with same padding and filter size and the downsampling is done by MaxPooling only?
True
False
Answer: 1 Explanation: Earlier models like AlexNet use large filter size in the beginning and downsampling was done either by max-pooling or by convolution. But in the VGG16 model, we have all the Conv layers with same padding and filter size and the downsampling is done by MaxPooling only. So what have we gained by using, for instance, a stack of three 3×3 conv. layers instead of a single 7×7 layer? First, we incorporate three non-linear rectification layers instead of a single one, which makes the decision function more discriminative. Second, we decrease the number of parameters. Refer to the Section 2.3 of this research paper to understand more.
Q5. 1×1 convolution can also help in decreasing the computation cost of a convolution operation?
True
False
Answer: 1 Explanation: 1×1 convolution can also help in decreasing the computation cost of a convolution operation. Refer to this beautiful explanation by Andrew Ng to understand more.
Q6. Can we use Fully Convolutional Neural Networks for object detection?
Yes
No
Answer: 1 Explanation: Yes a Fully Convolutional Neural Networks can be used for object detection. For instance, YOLO etc.
Q7. Which of the following networks can be used for object detection?
Overfeat
Faster RCNN
YOLO
All of the above
Answer: 4 Explanation: All of the above mentioned networks can be used for object detection. For instance, Faster RCNN belongs to Region based methods whereas YOLO, Overfeat belongs to sliding window based methods.
Q8. AlexNet was one of the first networks that uses ReLU activation function in the hidden layers instead of tanh/sigmoid (which were quite common at that time)?
True
False
Answer: 1 Explanation: This was one of the revolutionary ideas that boomed deep learning i.e. using ReLU activation function in the hidden layers instead of tanh/sigmoid (which were quite common at that time).
Answer: 3 Explanation: The values in a filter/mask are called as either coefficients or weights.
Q2. Which of the following networks uses the idea of Depthwise Separable Convolutions?
AlexNet
MobileNet
ResNet
VGG16
Answer: 2 Explanation: As mentioned in the MobileNet paper, MobileNets are based on a streamlined architecture that uses depthwise separable convolutions to build light weight deep neural networks that work even in low compute environment, such as a mobile phones. Refer to this research paper to understand more.
Q3. What is the output of a Region Proposal Network (RPN) at each sliding window location if we have k anchor boxes?
2k scores and 4k bounding box coordinates
4k scores and 2k bounding box coordinates
k scores and 4k bounding box coordinates
4k scores and 4k bounding box coordinates
Answer: 1 Explanation: In a Region Proposal Network (RPN), for k anchor boxes we get 2k scores (that estimate probability of object or not) and 4k bounding box coordinates corresponding to each sliding window location. Refer to Figure 3 of this research paper to understand more.
Q4. Which of the following networks uses Skip-connections?
DenseNet
ResNet
U-Net
All of the above
Answer: 4 Explanation: All of the above mentioned networks uses Skip-connections.
Q5. For binary classification, we generally use ________ activation function in the output layer?
Tanh
ReLU
Sigmoid
Leaky ReLU
Answer: 3 Explanation: For binary classification, we want the output (y) to be either 0 or 1. Because sigmoid outputs the P(y=1|x) and has value between 0 and 1, so it is appropriate for binary classification.
Q6. In ResNet’s Skip-connection, the output from the previous layer is ________ to the layer ahead?
added
concatenated
convoluted
multiplied
Answer: 1 Explanation: In ResNet’s Skip-connection, the output from the previous layer is added to the layer ahead. Refer to the Figure 2 of this research paper to understand more.
Q7. In Fast R-CNN, we extract feature maps from the input image only once as compared to R-CNN where we extract feature maps from each region proposal separately?
True
False
Answer: 1 Explanation: Earlier in R-CNN we were extracting features from each region proposals separately using a CNN and this was very time consuming. So, to counter this, in Fast R-CNN we extract feature maps from the input image only once and then project the region proposals onto this feature map. This saves a lot of time. Refer to this link to understand more.
Q8. For Multiclass classification, we generally use ________ activation function in the output layer?
Tanh
ReLU
Sigmoid
Softmax
Answer: 4 Explanation: For Multiclass classification, we generally use softmax activation function in the output layer. Refer to this beautiful explanation by Andrew Ng to understand more.
Q1. Which of the following object detection networks uses a ROI Pooling layer?
R-CNN
Fast R-CNN
YOLO
All of the above
Answer: 2 Explanation: Out of the above mentioned networks, only Fast R-CNN uses a ROI Pooling layer. Becuase of this, Fast R-CNN can take any size image as input as compared to R-CNN where we need to resize region proposals before passing into CNN. Refer to this research paper to understand more.
Q2. Which of the following techniques can be used to reduce the number of channels/feature maps?
Pooling
Padding
1×1 convolution
Batch Normalization
Answer: 3 Explanation: 1×1 convolution can be used to reduce the number of channels/feature maps. Refer to this beautiful explanation by Andrew Ng to understand more.
Q3. Which of the following networks has the fastest prediction time?
R-CNN
Fast R-CNN
Faster R-CNN
Answer: 3 Explanation: As clear from the name, Faster R-CNN has the fastest prediction time. Refer to this research paper to understand more.
Q4. Max-Pooling makes the Convolutional Neural Network translation invariant (for small translations of the input)?
True
False
Answer: 1 Explanation: According to Ian Goodfellow, Max pooling achieves partial invariance to small translations because the max of a region depends only on the single largest element. If a small translation doesn’t bring in a new largest element at the edge of the pooling region and also doesn’t remove the largest element by taking it outside the pooling region, then the max doesn’t change.
Q5. What do you mean by the term “Region Proposals” as used in the R-CNN paper?
regions of an image that could possibly contain an object of interest
regions of an image that could possibly contain information other than the object of interest
final bounding boxes given by the R-CNN
Answer: 1 Explanation: As clear from the name, Region Proposals are a set of candidate regions that could possibly contain an object of interest. These region proposals are then fed to a CNN which extracts features from each of these proposals and these features are then fed to a SVM classifier to determine what type of object (if any) is contained within the proposal. The main reason behind extracting these region proposals beforehand is that instead of searching the object at all image locations, we should search for only those locations where there is a possibility of object. This will reduce the false positives as we are only searching in the regions where there is a possibility of having an object. Refer to this research paper to understand more.
Q6. Because Pooling layer has no parameters, they don’t affect the gradient calculation during backpropagation?
True
False
Answer: 2 Explanation: It is true that Pooling layer has no parameters and hence no learning takes place during backpropagation. But it’s wrong to say that they don’t affect the gradient calculation during backpropagation because pooling layer guides the gradient to the right input from which the Pooling output came from. Refer to this link to know more.
Q7. Which of the following techniques was used by Traditional computer vision object detection algorithms to locate objects in images at varying scales and locations?
image pyramids for varing scale and sliding windows for varing locations
image pyramids for varing locations and sliding windows for varing scale
Answer: 1 Explanation: Becuase an object can be of any size and can be present at any location, so for object detection we need to search both at different locations and scales. As we know that by using image pyramids (multi-resolution representations for images) we can handle scale dependency and for locations we can use sliding window. So, traditional computer vision algorithms use these for object detection. For instance, refer to the Overfeat paper that shows how a multiscale and sliding window approach can be efficiently implemented within a ConvNet.
Q8. How do you introduce non-linearity in a Convolutional Neural Network (CNN)?
Using ReLU
Using a Max-Pooling layer
Both of the above
None of the above
Answer: 3 Explanation: Non-linearity can be introduced by either using ReLU (non-linear activation function) or by using a Max-Pooling layer (as max is a non-linear function).
Q1. Suppose we have an image of size 4×4 and we apply the Max-pooling with a filter of size 2×2 and a stide of 2. The resulting image will be of size:
2×2
2×3
3×3
2×4
Answer: 1 Explanation: Because in Max-pooling, we take the maximum value for each filter location so the output image size will be 2×2 (the number of filter locations). Refer to this beautiful explanation by Andrew Ng to understand more.
Q2. In Faster R-CNN, which loss function is used in the bounding box regressor?
L2 Loss
Smooth L1 Loss
Log Loss
Huber Loss
Answer: 2 Explanation: In Faster R-CNN, Smooth L1 loss is used in the bounding box regressor. This is a robust L1 loss that is less sensitive to outliers than the L2 loss used in R-CNN and SPPnet. Refer to Section 3.1.2 of this research paper to understand more.
Q3. For binary classification, we generally use ________ loss function?
Binary crossentropy
mean squared error
mean absolute error
ctc
Answer: 1 Explanation: For binary classification, we generally use Binary crossentropy loss function. Refer to this beautiful explanation by Andrew Ng to understand more.
Q4. How do we perform the convolution operation in computer vision?
we multiply the filter weights with the corresponding image pixels, and then sum these up
we multiply the filter weights with the corresponding image pixels, and then subtract these up
we add the filter weights and the corresponding image pixels, and then multiply these up
we add the filter weights with the corresponding image pixels, and then sum these up
Answer: 1 Explanation: In Convolution, we multiply the filter weights with the corresponding image pixels, and then sum these up.
Q5. In a Region Proposal Network (RPN), what is used in the last layer for calculating the objectness scores at each sliding window position?
Softmax
Linear SVM
ReLU
Sigmoid
Answer: 1 Explanation: In a Region Proposal Network (RPN), the authors of Faster R-CNN paper uses a 2 class softmax layer for calculating the objectness scores for each proposal at each sliding window position.
Q6. In R-CNN, the regression model outputs the actual absolute coordinates of the bounding boxes?
Yes
No
Answer: 2 Explanation: In R-CNN, the regression model outputs the deltas or the relative coordinate change of the bounding boxes instead of absolute coordinates. Refer to Appendix C of this research paper to understand more.
Q7. Is Dropout a form of Regularization?
Yes
No
Answer: 1 Explanation: Dropout, applied to a layer, consists of randomly dropping out(setting to zero) a number of output features of the layer during training. Because as any node can become zero, we can’t rely on any one feature so have to spread out the weights similar to regularization.
Q8. A fully convolutional network can be used for
Image Segmentation
Object Detection
Image Classification
All of the above
Answer: 4 Explanation: We can use a fully convolutional network for all of the above mentioned tasks. For instance, for image segmentation we have U-Net, for object detection we have YOLO etc.
Q1. Which of the following is not a good evaluation metric for Multi-label classification?
Mean Average Precision at K
Hamming Score
Accuracy
Top k categorical accuracy
Answer: 3 Explanation: Accuracy is not a good evaluation metric for Multi-label classification. As we know in multi-label each example can be assigned to multiple classes so let’s say if the predicted output was [0, 0, 0, 0, 1, 1,0] and the correct output was [1, 1, 0, 0, 0, 0, 0], my accuracy would still be 3/6 but it should be 0 as it is not able to predict any of the classes correctly.
Q2. Which of the following are the hyperparameters for a Pooling layer?
filter size
stride
which type of Pooling to use (max or average)
All of the above
Answer: 4 Explanation: All of the above mentioned are the hyperparameters for a Pooling layer.
Q3. Images are an example of ________ data?
Structured
Unstructured
Answer: 2 Explanation: Structured data refers to the type of data where each feature has a well defined meaning and opposite is true for unstructured data. So, images are an example of unstructured data.
Q4. For image classification, MaxPooling tends to works better than average pooling?
Yes
No
Answer: 1 Explanation: Because in image classification our main aim is to identify whether a feature is present or not so MaxPooling tends to works better than average pooling.
Q5. What is Pointwise Convolution?
1×1 convolution
Strided Convolution
convolution followed by MaxPool
convolution followed by Dropout
Answer: 1 Explanation: According to the MobileNet paper, “After depthwise convolution, The pointwise convolution then applies a 1×1 convolution to combine the outputs of the depthwise convolution.”. Refer to Section 3.1 of this research paper to understand more.
Q6. What is a Region Proposal network?
a fully convolutional network that simultaneously predicts object bounds and objectness scores at each position
a fully connected network that simultaneously predicts object bounds and objectness scores at each position
a fully convolutional network that predicts only the objectness scores at each position
a fully connected network that predicts only the object bounds at each position
Answer: 1 Explanation: According to the Faster R-CNN paper, Region Proposal network (RPN) is a fully convolutional network that takes an image(of any size) as input and outputs a set of rectangular object proposals, each with an objectness score. Refer to Section 3.1 of this research paper to understand more.
Q7. In MobileNetv2, the Depthwise Separable Convolutions are replaced by _________ ?
Normal Convolution
Strided Convolution
Bottleneck Residual Block (Inverted Residuals and Linear Bottleneck)
Residual Blocks
Answer: 3 Explanation: In MobileNetv2, the Depthwise Separable Convolutions are replaced by Bottleneck Residual Block (Inverted Residuals and Linear Bottleneck). Refer to Table 1 of this research paper to understand more.
Q8. Can we use Convolutional Neural Networks for image classification?
Yes
No
Answer: 1 Explanation: Generally, Convolutional Neural Networks are preferred for any image related tasks such as image classification, object detection etc.
Q1. Let say if you have 10 million dataset, and it would take 2 week time to train your model. Which of the following statement do you most agree with?
If you have already trained a model with different dataset and is performing well with 98% dev accuracy on that dataset, you just use that model instead of training on current dataset for two weeks
If 10 million dataset is enough to build a good model, you might be better off training with just 1 million dataset to gain 10 times improvement in how quickly you can run experiments, even if each model performs a bit worse because it’s trained on less data
You will go with complete dataset and run the model for two weeks to see the first results
All of the above
Answer: 2 Explanation: In Machine learning, the best approach is to build an initial model quickly using a random subset of data and then use the Bias/Variance analysis and error analysis to priortize next steps.
Q2. In a Multi-layer Perceptron (MLP), each node is connected to all the previous layer nodes?
True
False
Answer: 1 Explanation: Since a Multi-Layer Perceptron (MLP) is a Fully Connected Network, each node in one layer connects with a certain weight to every node in the following layer.
Q3. Identify the following activation function : g(z) = (exp(z) – exp(-z))/(exp(z) + exp(–z))?
Tanh activation function
Sigmoid activation function
ReLU activation function
Leaky ReLU activation function
Answer: 1 Explanation: This refers to Tanh activation function. Similar to sigmoid, the tanh function is continuous and differentiable at all points, the only difference is that it is symmetric around the origin. Refer to this beautiful explanation by Andrew Ng to know more.
Q4. Suppose we have a neural network having 10 nodes in the input layer, 5 nodes in the hidden layer and 1 node in the output layer. What will be the dimension of W1 (first layer weights) and W2 (second layer weights)?
W1:5×1, W2:1×1
W1:1×10, W2:1×5
W1:1×5, W2:5×10
W1:5×10, W2:1×5
Answer: 4 Explanation: Generally, the weights dimensions for a layer is (next layer nodes x previous layer nodes) so the answer is W1:5×10, W2:1×5. Refer to this beautiful explanation by Andrew Ng to know more.
Q5. In Dropout, What will happen if we increasing the Dropout rate from (say) 0.5 to 0.8?
Reducing the regularization effect.
Causing the neural network to end up with a lower training set error.
Both of the above.
None of the above.
Answer: 3 Explanation:
Q6. Finding good hyperparameter values is very time-consuming. So typically you should do it once at the start of the project, and try to find very good hyperparameters so that you don’t ever have to revisit tuning them again.
True
False
Answer: 2 Explanation: You can’t really know beforehand which set of hyperparameters will work best for your case. You need to follow the iterative process of Idea->Code->Eperiment.
Q7. In a deep neural network, what is the general rule for the dimensions of weights and biases of layer l? Where n is the number of units in layer l.
w[l] : (n[l], n[l]) b[l] : (n[l], 1)
w[l] : (n[l+1], n[l]) b[l] : (n[l-1], 1)
w[l] : (n[l], n[l-1]) b[l] : (n[l], 1)
w[l] : (n[l], n[l-1]) b[l] : (n[l-1], 1)
Answer: 3 Explanation: The dimensions of weights of layer l is given by (n[l], n[l-1]) and biases is given by (n[l], 1). Refer to this beautiful explanation by Andrew Ng to know more.
Q8. Which of the following method can be used for hyperparameter tuning?
Random Search
Grid Search
Bayesian optimization
All of the above.
Answer: 4 Explanation: All of the above methods can be used for hyperparameter tuning.
Q1. What will be the output of the following code:
1
len("AILearner")
8
9
10
Error!
Answer: 2 Explanation: In Python language, len() function gives the length of an object. When the object is a string, it will output the number characters in the string.
Answer: 4 Explanation: D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple. But in this question only one argument is given to popitem() method.
Q4. Which of the following statements is not true?
We can change the value of a private variable of superclass in the subclass
Superclass non-private method can be overridden.
The constructor of a class in invoked automatically.
A derived class is a subclass of superclass
Answer: 1 Explanation: We can not change the value of a private variable of superclass in the subclass.
Q5. What type of error will be raised when the imported module is not found?
ImportError
NullPointerError
NameError
IndexNotFoundError
Answer: 1 Explanation: ImportError will be raised when the imported module is not found.
Q6. How does Python treat a string literal when it is not assigned to any variable?
It will ignore the string literal.
It will automatically assings a variable to it.
It will through an error.
None of the above.
Answer: 1 Explanation: In Python language, if you do not assign a string literal to a variable, it will ignore the string literal while in other languages like Java it will throw a compile time error.
Q7. In Python, which of the following variable is not of a integer data type?
x = 435757438
x = 5
x = 23.45
x = -5
Answer: 3 Explanation: Int is a whole number, it can be either positive or negative. It can not have decimal values also it can be of unlimited length.
Q8. Which of the following statement will extract the percentage of the mentioned student?
Answer: 2 Explanation: json.loads() method can be used to parse a valid JSON string and convert it into a Python Dictionary. json.loads() in Python => print(data[‘School’][‘student’][‘result’][‘percentage’]) => 70%
Special method __add()__ is called when + operator is used.
In Python, same operator may behave differently depending upon operands.
__init__() function is called when a new object is instantiated.
All of the above
Answer: 4 Explanation: All of the given three options are correct.
Q2. In Python, which of the following statement will print a random number between 1 and 10 (both 1 and 10 included)?
print(random.randrange(1, 10))
print(random.random(1, 10))
print(random.randint(1, 10))
None of the above.
Answer: 3 Explanation: 1. print(random.randrange(1, 10)) -> This will print a random integer between 1 and 10 where 10 is not included. 2. print(random.random(1, 10)) -> This will throw an error because random does not take any argument but two are given. 3. print(random.randint(1, 10)) -> This will print a random number between 1 and 10 (both 1 and 10 included).
Q3. Which of the following is not true of global variable in Python?
global keyword can be used to create a global variable inside a local scope.
Accessible only in the block they are defined in.
A variable created in the main body of the Python code is a global variable.
Accessible from anywhere in the script.
Answer: 2 Explanation: Global variables are available from within any scope, either it is global or local.
Q4. If x = 2**4/2+3-1, then what will be the data type of x?
int
float
Answer: 2 Explanation: Division operator is used in x = 2**4/2+3-1 and division operator gives the value including the decimals which will be of float data type.
Q5. Which of the following method can be used to combine strings and numbers?
concatenate()
join()
append()
format()
Answer: 4 Explanation: The format() method format the passed arguments and places them in the string according to the placeholders {}. Fancier Output Formatting
Q6. Suppose x = 6.3, then which of the following statement will throw an error?
y = float(x)
y = int(x)
y = complex(x)
None of the above.
Answer: 4 Explanation: int, float and complex are numeric data types. These will cast ‘x’ into it’s respective data types.
Q7. What will be the output of print(ord(‘the’))?
116 104 101
116 116 116
104 104 104
TypeError
Answer: 4 Explanation: Python ord() function returns the Unicode code from a given character. This function accepts a string of unit length as an argument and returns the Unicode equivalence of the passed argument. Reference: ord() function in Python
Q8. In Python, which of the following character is used to add at the start of a line to make it a comment?
#
“
//
&
Answer: 1 Explanation: In Python language comments start with # and the rest of the line will be rendered as comment.
string="The current world population is 7.9 billion as of December 2021"
y=[xforxin(xforxinstringifx.isdigit())]
print(y)
[7, 9, 2, 0, 2, 1]
[‘7’, ‘9’, ‘2’, ‘0’, ‘2’, ‘1’]
[7, 2, 0, 2, 1]
Runtime error!
Answer: 2 Explanation: This is an example of list comprehension in Python. List comprehensions are used for creating new lists from other iterables like tuples, strings, arrays, lists, etc. A list comprehension consists of brackets containing the expression, which is executed for each element along with the for loop to iterate over each element. List Comprehensions
Q2. What are the name of the operators |, &, >> and << respectively?
AND, OR, RIGHT SHIFT and LEFT SHIFT
AND, OR, LEFT SHIFT and RIGHT SHIFT
OR, AND, LEFT SHIFT and RIGHT SHIFT
OR, AND, RIGHT SHIFT and LEFT SHIFT
Answer: 4 Explanation: OR, AND, RIGHT SHIFT and LEFT SHIFT are name of the |, &, >> and << operators respectively.
Q3. What will be the output of following code:/code/
1
2
3
4
a=[1,2]
b=a
b+=[3,4]
print(a,b)
[1, 2] [1, 2, 3, 4]
[1, 2, 3, 4] [1, 2, 3, 4]
[1, 2, 3, 4] [1, 2]
[1, 2] [3, 4]
Answer: 2 Explanation: In Python language, assigning one variable to another variable creates an alias of each variable. Here variable b is an alias of variable a. It means both variable a and b points to the same object in the memory. That’s why when you are updating the value of variable b, value of variable a is also changing.
Q4. Python is an object oriented programming language.
True
False
Answer: 1 Explanation: Python is an object oriented programming language. Almost everything in Python is an object. A class in Python is a blueprint for creating objects.
Q5. What will be the output of following code:
1
2
3
num=(1,2,3,4,5)
(a,b,*c)=num
print(a,b,c)
1 2 (3, 4, 5)
1 2 3
1 2 [3, 4, 5]
ValueError
Answer: 3 Explanation: *variable is basically extended iterable unpacking. It will assign a list of all items not assigned to a regular variable name. So from tuple “num”, 1 is assinged to a, 2 is assigned to b and rest all items will be assigend as list to c. Extended Iterable Unpacking
Q6. Which of the following statement is the correct way of assigning an integer value to a variable in Python?
x = ‘6’
int x = 6;
x = 6
Integer x = 6;
Answer: 3 Explanation: x = ‘6’ -> will create a string data type. int x = 6; and Integer x = 6; -> It is a way of assignment and declaration in Java language.
In Python there is no need to declare the data type using int or Integer. It will create a variable with respect to the type of data you assing to it.
Q7. What is the syntax for multiline comment in Python?
Use /* at the start of the first line and use */ at the end of the last line.
Use <-- at the start of the first line and use --> at the end of the last line.
Python does not have syntax for multiline comment. You can either use # at the start of every line or make it as multiline string (triple quote).
None of the above.
Answer: 3 Explanation: Since Python does not have syntax for multiline comments, there is a workaround. As Python ignores the string literal if it is not assigned to a variable, we can add multiline string in our code and place the multiline comment inside it.
Q8. What will be the output of following code:
1
2
3
4
5
6
7
8
i=1
whilei<5:
print(i,end=" ")
i+=1
ifi==4:
break
else:
print(i+1)
1 2 3
1 2 3 4
1 2 3 5
1 2 3 4 5
Answer: 1 Explanation: while loop executes the block until a condition is satisfied. When the condition becomes false, the statement immediately after the loop is executed. The else clause is only executed when your while condition becomes false. If you break out of the loop, or if an exception is raised, it won’t be executed. Reference: While Loop
Q1. if x = [1, 2, 5, 3, 4], what will be the output of print(x[0:3:2])?
[1, 5, 4]
[1, 5]
[1, 2, 5, 3, 4]
List index out of range exception!
Answer: 2 Explanation: Slice in Python list here refer to list[::]. So x[0:3:2] will start at index 0, stop at index 3 at take a step of 2.
Q2. What is the difference between a method and a function in Python?
Functions can be called only by its name but methods can not be called by its name only.
we don’t need a class to define a function but methods are defined inside a class.
Functions are independent entities in a program while methods are dependent on the class they belong to.
All of the above.
Answer: 4 Explanation: All the given three options are correct.
Q3. What will be the output of following code:
1
2
3
x=[10,20,30,40]
x+=[10]
print(x)
[20, 30, 40, 50]
[10, 20, 30, 40, 10]
Answer: 2 Explanation: In Python language, + operator append the elements to the original array.
Q4. What will be the output of following code:
1
2
3
def fun(x=3,y):
print(x,y)
fun(2)
3 2
2 2
2 3
SyntaxError
Answer: 4 Explanation: It will raise an error. In function definition, non-default arguments should be written before the default arguments.
Q5. Which of the following is true when you open a file using with keyword?
File reading and writing are faster using the with statement.
The file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.
You need not to handle exception anymore in the whole script.
Answer: 2 Explanation: When you open a file using with keyword, the file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.
Q6. A class can serve as base class for many derived classes.
True
False
Answer: 1 Explanation: yes a class can serve as base class for many derived classes. It is also call as Hierarchical inheritance.
Q7. The following code will throw an error.
1
2
3
def fun(**x):
print(x[a])
fun(a=1,b=2,c=3)
True
False
Answer: 1 Explanation: **kwargs are used as arbitrary keyword arguments. If we do not know how many keyword arguments that will be passed into our function then we can add two asterisk ** before the parameter name in the function definition. In the given function definition x will be a dictinary of arguments. That’s why print(x[a]) will raise an error.
Q8. Which of the following statement will create a variable of string type?
a = ”’AILearner”’
a = “AILearner”
a = ‘AILearner’
All of the above.
Answer: 4 Explanation: In Python language, a string can be created by using any of the single, double or triple quotation marks. Usually three quotes are used to create a multiline string.