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.
Negative indexes begin toward the end of a string and go in reverse.
x * = y * x + 1 means x = x * (y * x + 1)
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 - what is output of following code −
class Count: def __init__(self, count=0): self.__count=count a=Count(2) b=Count(2) print(id(a)==id(b), end = '' '') c= ''hello'' d= ''hello'' print(id(c)==id(d))
The objects with same contents share the same object in the python library but this is not true for custom-defined immutable classes.
Q 5 - What is output of following −
print(''abbzxyzxzxabb''.count(‘abb’,-10,-1))
It Counts the number of times the substring ‘abb’ is present starting from position 2 and ending at position 11 in the given string.
Q 6 - What is the output of the following code?
eval(''1 + 3 * 2'')
Eval is a method used to evaluate the values entered in the braces.
Q 7 - Suppose we are given with two sets(s1&s2) then what is the output of the code −
S1 + S2
A - Adds the elements of the both the sets.
+ Operator cannot be operated on the sets.
Q 8 - Which function can be used on the file to display a dialog for saving a file?
B - Filename = asksavefilename()
This is the default method to display a dialog for saving a file in Tkinter module of Python.
Q 9 - Select the valid code to bind a canvas with a key event p −
Q 10 - We can create an image in canvas. Select the option to do so?
A - Image = PhotoImage(imagefilename)
B - Canvas.create_image(filename)