41. How can you create a private attribute in a Python class?
42. What will be the output of the following Python code?
def add(c,k):
c.test=c.test+1
k=k+1
class A:
def __init__(self):
self.test = 0
def main():
Count=A()
k=0
for i in range(0,25):
add(Count,k)
print("Count.test=", Count.test)
print("k =", k)
main()
def add(c,k):
c.test=c.test+1
k=k+1
class A:
def __init__(self):
self.test = 0
def main():
Count=A()
k=0
for i in range(0,25):
add(Count,k)
print("Count.test=", Count.test)
print("k =", k)
main()
43. Which function overloads the // operator?
44. What will be the output of the following Python code?
class test:
def __init__(self,a):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()
class test:
def __init__(self,a):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()
45. What will be the output of the following Python code?
class Demo:
def __init__(self):
pass
def test(self):
print(__name__)
obj = Demo()
obj.test()
class Demo:
def __init__(self):
pass
def test(self):
print(__name__)
obj = Demo()
obj.test()
46. Special methods need to be explicitly called during object creation.
47. Which of the following is not a class method?
48. What is the purpose of the super() function in Python classes?
49. What will be the output of the following Python code?
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+1)
print(x.a)
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+1)
print(x.a)