Q1 . A class definition in python begins with the keyword –
(a): def , file
(b): class , object
(c): self , py file
(d): None of these
Answer: (b) class , object
Q2 . What will be the output of the following python code ?
class Roll:
def __init__(self, id):
self.id = id
id = 231
return id
val = Roll(321)
print (val.id)
(a): TypeError
(b): 231
(c): 321
(d): None of these
Answer: (b): 231
Q3 . What will be the output of following python code?
class X:
def __init__(self):
self.a = 10
self._b = 20
def getB(self):
return self._b
x = X()
x._b = 60
print(x.getB())
(a): 20
(b): 60
(c): Error
(d): Program runs but does not print anything
Answer: (b) 60
Q4 . Private method starts with _______ while protected method starts with ________.
(a).#,@
(b).double underscore,single underscore
(c).single underscore , double underscore
(d).None of these
Answer:- (b).double underscore,single underscore.
Q5 . what will be the output of the following code. code is saved in a file named 'code.py'
f = open(‘file.txt’)
f, readlines()
print(f. name)
print ( f.closed )
f.close()
print ( f.closed ).
(a).Error in code
(b). true
false
true
(c). code.py
False
True
(d)file.txt
False
True
Answer;- (d)file.txt
False
True
0 Comments