In python, a class is created by ____ keyword, and to create ____ of the class, we will have to use constructor of class.
1.
2.
3.
4.
Q:2. 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)
1.
2.
3.
4.
shows Error because _init_() should return None, not 'int'.Q:3. What will be the output of following python code?
class X:
def __init__(self):
self.a = 10
self._b = 20
self.b = 20
def getB(self):
return self.b
x = X()
x._b = 60
print(x.getB())
1.
2.
3.
4.
Q:4. Private method in python starts with ____ while protected methods starts with ____ .
1.
2.
3.
4.
to define a private method prefix member name with double underscore,whlie protected method starts with single underscore.Q:5. 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 )
1.
2.
3.
4.
0 Comments