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 the output for −
'Tutorials Point' [100:200]?
Slicing will never give us an error even if we give it too large of an index for the string. It will just return the widest matching slice it can.
Q 2 - What is output for −
b = [11,13,15,17,19,21]
b[::2] :- it iterates over the list with ‘2’ increments
Q 3 - When the given code is executed how many times ' 'you are learning python ' ' will be printed.
a = 0 while a<10: … print(''you are learning python'') … pass
The loop will execute infinite number of times because there is no statement specified for end of loop and pass indicates nothing is to be done.
Q 4 - How can we check whether the object is instance of class or not. Let us consider an object O which is instance of class B.
isinstance() method is used to find whether the object is instance of class or not.
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 - 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 - Suppose we are given with two sets(s1&s2) then what is the output of the code −
S1 + S2
+ Operator cannot be operated on the sets.
Q 8 - Which code is used to open a file for binary writing?
‘b’ format is used to work on the binary format of file.
Q 9 - Which code can be used as an input dialog named ''Is this a character? ''
Q 10 - We can create an image in canvas. Select the option to do so?