21. Find the output :
class stud:
'Base class for all students'
def __init__(self, roll_no, grade):
self.roll_no = roll_no
self.grade = grade
def display (self):
print("Roll no : ", self.roll_no, ", Grade: ", self.grade)
print(stud.__doc__)
a. Exception is thrown
b. __main__
c. Nothing is displayed
d. Base class for all students
View Answer
Ans. d
Explanation : __doc__ that provides a documentation of the object.
22. Find the output :
a = (1, 2)
a[0] +=1
a. (1,1,2)
b. 2
c. Type Error
d. Syntax Error
View Answer
Ans. c
Explanation : ‘tuple’ object does not support item assignment
23. Find the output :
class Test:
def __init__(self):
self.x = 0
class Derived_Test(Test):
def __init__(self):
self.y = 1
def main():
b = Derived_Test()
print(b.x,b.y)
main()
a. 0 1
b. 0 0
c. Error
d. 1 0
View Answer
Ans. c
Explanation : ‘Derived_Test’ object has no attribute ‘x’
24. Which of the following can help us to find the version of python that we are currently working on?
a. sys.version
b. sys.version()
c. sys.version(0)
d. sys.version(1)
View Answer
Ans. a
Explanation : This is the correct syntax
25. Find the output :
class change:
def __init__(self, x, y, z):
self.a= x - y * z
x =change(1,2,3)
y =getattr(x,'a')
setattr(x,'a', y)
print(x.a)
a. 6
b. -5
c. Error
d. 0
View Answer
Ans. b
Explanation : a = 1 – (2*3) => -5
The getattr() method returns the value of the named attribute of an object.
The setattr() function sets the value of the attribute of an object.