1000 Python quiz
1 - What is output for −
raining'. find('z') ?
A - Type error
B - ' '
C - -1
D - Not found
Answer : C
Explanation
If the string is not found by method find() , it returns the integer -1.
2 - What is output of following code −
num=3
while True:
if (num%0o12 == 0):
break
print(num)
num += 1
A - 3 4 5 6 7 8 9 10 11 12
B - 3 4 5 6 7 8 9
C - 3 4 5 6 7 8 9 10 11
D - None of the above
Answer : B
Explanation
we are getting output 3 to 9 because 0o12 is octal number.
3 - For tuples and list which is correct?
A - List and tuples both are mutable.
B - List is mutable whereas tuples are immutable.
C - List and tuples both are immutable.
D - List is immutable whereas tuples are mutable.
Answer : B
Explanation
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.
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))
A - True False
B - False True
C - False False
D - True True
Answer : B
Explanation
The objects with same contents share the same object in the python library but this is not true for custom-defined immutable classes.
5 - What is output of following −
print(''abbzxyzxzxabb''.count(‘abb’,-10,-1))
A - 2
B - 0
C - 1
D - Error
Answer : B
Explanation
It Counts the number of times the substring ‘abb’ is present starting from position 2 and ending at position 11 in the given string.
6 - Guess the output −
def main():
try:
func()
print(''print this after function call'')
except ZeroDivisionError:
print('Divided By Zero! Not Possible! ')
except:
print('Its an Exception!')
def func():
print(1/0)
main()
A - ‘Its an Exception!’
B - ‘Divided By Zero! Not possible!’
C - ‘print this after function call’ followed by ‘Divided By Zero! Not Possible!’
D - ‘print this after function call’ followed by ‘Its an Exception!’
Answer : B
Explanation
The function ‘func’ will not run because it contains an exception. So in try and expect block. The function called under try will not run and will move to except block which defines the type of exception present in the function ‘func’. Thus block of statements present in except ZeroDivisionError is printed.
7 - Suppose you are given a set(s1={1,2,3}) then what is the output for the code −
2 * s1?
A - (1,1,2,2,3,3)
B - [1,1,2,2,3,3]
C - Illegal
D - (1,2,3,1,2,3)
Answer : C
Explanation
* cannot be operated on the sets.
8 - How to create a frame in Python?
A - Frame = new.window()
B - Frame = frame.new()
C - Frame = Frame()
D - Frame = window.new()
Answer : C
Explanation
Frame() method is used to make a frame in python.
9 - Which code can be used as an input dialog named ''Is this a character? ''
A - Tkinter.messagebox.showinfo(''showinfo'' , ''Is this a character? '')
B - Tkinter.messagebox.askyesno(''askyesno'' , ''Is this a character? '')
C - Tkinter.messagebox.showerror(''showerror'' , ''Is this a character? '')
D - Tkinter.messagebox.showwarning(''showwarning'' , ' 'Is this a character? '')
Answer : B
10 - How you can lift the pen of in turtle?
A - Turtle.lift()
B - Turtle.liftup()
C - Turtle.penup()
D - Turtle.up()
Answer : C
11. Predict the output of following python programs:
r = lambda q: q * 2
s = lambda q: q * 3
x = 2
x = r(x)
x = s(x)
x = r(x)
print (x)
Output:
24
Comments
Post a Comment