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 - What is the output of following code −
[ (a,b) for a in range(3) for b in range(a) ]
This is nested for loop. The output of first for loop will be the value for the next loop.
Q 3 - For tuples and list which is correct?
list are mutable whereas tuples are immutable i.e. in list changes can be made but in tuples it is not possible, they can only be operated its value cannot be changed.
2**3 gives 2*2*2 i.e. 8, then 2*8 gives 16, since order of precedence is ** then*. ** implies ‘‘ raise to power’’.
encode() returns bytes object.
Q 6 - Which among them is used to create an object?
constructor is used to create an object of class.
Q 7 - Discuss the outcome of the code?
def func1(n): if(n==0): return 0 else: return(n+func1(n-1)) def func2(n, result): if(n==0): return(result) else: return(func2(n-1, n+result)) print(func1(4)) print(func2(4,0))
A function call is said to be tail recursive if there is nothing to do after the function returns except return its value.
Q 8 - Select the correct code to create a check button under parent frame1 and it should be bind to v1?
Checkbutton method is used to make a checkbox. In the parameters we need to pass the values as asked in the question. Here it should bind to v1 thus variable is set to v1 and frame should be under frame1 thus frame1 mentioned in the code.
Q 9 - Which code can be used as an input dialog named ''Is this a character? ''
Because Identifiers start from letter A to Z or a to z or an underscore (_) followed by more letters or zero or underscores and digits (0 to 9). Python does not allow @ or $ or % within the identifier.