Font size
WorksheetsSeason 4 #Spaic Python Weekly Quiz
Total questions: 20
Worksheet time: 11mins
How are lambda functions useful? Select all that apply:
Lambda functions make it easy to read the code.
They are useful in allowing quick calculations or processing as the input to other functions.
They can be useful as quick, throwaway single-line functions.
Lambda functions are used for functional programming.
What are the common functional programming methods that use lambdas? Select all that apply:
reduce()
filter()
map()
lookup()
What would be the output of the following code snippet?
(lambda x: (x + 3) * 5 / 2)(3)
0
SyntaxError
30.0
15.0
Which of the following are true for objects of Python’s set type:
The order of elements in a set is significant.
A set may contain elements that are mutable.
A given element can’t appear in a set more than once.
Sets are mutable.
What is the result of this statement:
{'q', 'r', 'x', 'u', 'b', 'a'}
{}
set()
{'b', 'r', 'a'}
What is the output from this print() function call:
3 1 2
3 2 1
3 1 1
3 1 0
What are the modules that must be imported when using scikit-Learn for Linear regression :
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
from sklearn import preprocessing
All the above
X = data[['TV', 'Radio', 'Newspaper']]
y = data['Sales']
How can we split the data into training and testing sets :
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
train_test_split(X, y, random_state=1)
X_train, y_train= train_test_split(X, y, random_state=1)
None of the above
To train the data in LinearRegression :
# instantiate
linreg = LinearRegression()
# fit the model to the training data (learn the coefficients)
linreg.fit(X_train, y_train)
True
False
To print the intercept and coefficients after the training of Linear regression : print(linreg.intercept) , print(linreg.coef)
True
False
To calculate the metrics for linear regression in scikit-learn :
# calculate Mean Absolute Error
print(metrics.mean_absolute_error(true, pred))
# calculate Mean Squared Error
print(metrics.mean_squared_error(true, pred))
# calculate Root Mean Squared Error
print(np.sqrt(metrics.mean_squared_error
(true, pred)))
All the above
If a=[1,2,3,4,5] what will be the result of following code?
print(a[1::-1])
[5,4]
[2,1]
[3, 2]
[4]
Is the following Python code valid?
Yes, [1,2,3] is printed
No, invalid syntax
Yes, (1,2,3) is printed
1 is printed
What will be the output of the following Python code?
>>>"Welcome to Python".split()
[“Welcome”, “to”, “Python”]
(“Welcome”, “to”, “Python”)
{“Welcome”, “to”, “Python”}
“Welcome”, “to”, “Python”
Suppose list1 is [1, 3, 2], What is list1 * 2?
[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
Say s=”hello” what will be the return value of type(s)?
int
bool
str
String
What will be the output of the following Python statement?
>>>"abcd"[2:]
a
ab
cd
dc
What will be the output of the following Python code?
{1: 5}
{1: 5, 2: 3}
Error, syntax error for pop() method
{1: 5, 3: 4}
Read the following Python code carefully and point out the global variables?
x
y and z
x, y and z
Neither x, nor y, nor z
Is the following Python code correct?
True
False
