General Python Quiz
Answer : C
the correct file extension for Python files is .py
Q 2 - Which of the following expressions is an example of type conversion?
Answer : A
Explanation
Type conversion is nothing but explicit conversion of operands to a specific type. Options 5.3 + 6.3 and 5.0 + 3 are examples of implicit conversion whereas option 4.0 + float(3) is an example of explicit conversion or type conversion.
Answer : B
Explanation
The value of the expression (2**2)**3 = 4**3 = 64. When the expression 2**2**3 is evaluated in python, we get the result as 256, because this expression is evaluated as 2**(2**3). This is because the associativity of exponentiation operator (**) is from right to left and not from left to right.
Q 4 - What is the output of the following function call
def outer_fun(a, b): def inner_fun(c, d): return c + d return inner_fun(a, b) return a result = outer_fun(5, 10) print(result)
Answer : A
Explanation
Adding multiple return statements doesn’t perform any task. Once function execution is encountered with the return statement, it stops the execution by returning whatever specified by the return statement.
Q 5 - The output of which of the codes shown below will be: “There are 4 blue birds.”?
A ) ‘There are %g %d birds.’ %4 %blue
B ) ‘There are %s %d birds.’ %[4, blue]
Answer : D
Explanation
The code ‘There are %d %s birds.’ %(4, blue) results in the output: There are 4 blue birds. When we insert more than one value, we should group the values on the right in a tuple.
Q 6 - What is the output of the following code?
sampleList = ["Junior", "Mason", "Nelson"] sampleList.append(2, "Gideon") print(sampleList)
A ) [‘Junior’, ‘Mason’, ‘Gideon’, ‘Nelson’]
Answer : B
Explanation
The append() method appends an item to the end of the list. Therefore, we cannot pass the index number to it.
Q 7 - The formatting method {1:<10} represents the ___________ positional argument, _________ justified in a 10 character wide field.
Answer : D
Explanation
The formatting method {1:<10} represents the second positional argument, left justified in a 10 character wide field.
Q 8 - The ______ symbol along with the name of the decorator function can be placed above the definition of the function to be decorated works as an alternate way for decorating a function.
Answer : B
Explanation
The @ symbol along with the name of the decorator function can be placed above the definition of the function to be decorated works as an alternate way for decorating a function.
Q 9 - What arithmetic operators cannot be used with strings?
Answer : B
Explanation
+ is used to concatenate and * is used to multiply strings.
Q 10 - What is the value of x
x = 0 while (x < 100): x+=2 print(x)
0 Comments