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 = ['hat', 'mat', 'rat']
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 - How can we swap two numbers a = 10, b = 20 in python without using third variable?
b = a
a = b
To swap two numbers we can use both a & b option. Both a & b are similar statemnts written in different ways.
Q 3 - Name the error that doesn’t cause program to stop/end, but the output is not the desired result or is incorrect.
logical error doesn’t cause the program to stop/end, but the output is not the desired result or is incorrect.
Q 4 - What is output of following code −
def func(n): if(n==1): return 1; else: return(n+func(n-1)) print(func(4))
encode() returns bytes object.
Q 6 - Analyze the given below code?
class Demo: def __init__(self,d): self.d=d def print(self): print(d) a = Demo(''Hello'') a.print()
D stores the argument value here. Thus when we call the class ‘‘Hello’’ is passed as an argument which is stored in the variable d.
Q 7 - What is the out of the code?
def rev_func(x,length): print(x[length-1],end='' '') rev_func(x,length-1) x=[11, 12, 13, 14, 15] rev_func(x,5)
In the print statement of rev_func we use the index value of list x. We decrement the value of length of function because it becomes the index of x in the print statement.
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 code can be used as an input dialog named ''Is this a character? ''
Q 10 - Select the code for the following output?