Following quiz provides Multiple Choice Questions (MCQs) related to Python. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.
Q 1 - What is output for −
a = ['he', 'she', 'we']
The method join() takes list of string as input and returns string as output. It removes ', ' and add the given string with join to the list.
Q 2 - What is output for −
b = [11,13,15,17,19,21]
b[::2] :- it iterates over the list with ‘2’ increments
‘=‘ operator is right associative as assignment operators are right associative.
Q 4 - What is output of following code −
def func(x, ans): if(x==0): return 0 else: return func(x-1, x+ans) print(func(2,0))
Q 5 - What is the output of the following code?
def nprint(message, n): while(n > 0): print(message) n-=1 nprint('z', 5)
Because decrementing condition of ‘n’ is not present in the while loop.
Q 6 - What happens in the below code?
class A: def __init__(self, i=100): self.i=i class B(A): def __init__(self,j=0): self.j=j def main(): b= B() print(b.i) print(b.j) main()
Reason being that i is initiated with self thus making it a instantiate variable of that class which cannot be inherited by the above way.
Q 7 - Analyze the code −
print(''Recursive Function'') def factorial(n): return(n*factorial(n-1)) factorial(4)
there is no condition in the code to stop the function.
Q 8 - Which method is used to convert raw byte data to a string?
Decode is the method used to convert the raw byte data to a string.
Q 9 - Which way among them is used to create an event loop ?
Q 10 - Select the code for the following output?