61. How can you create a static variable in a Python class?
62. What will be the output of the following Python code?
>>> class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__ built-in function called'
>>> s=demo()
>>> print(s)
>>> class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__ built-in function called'
>>> s=demo()
>>> print(s)
63. What is the purpose of the @property decorator in Python classes?
64. What is the output of the following code:
class MyClass:
count = 0
def init(self):
MyClass.count += 1
obj1 = MyClass()
obj2 = MyClass()
print(obj1.count)
class MyClass:
count = 0
def init(self):
MyClass.count += 1
obj1 = MyClass()
obj2 = MyClass()
print(obj1.count)
65. What will be the output of the following Python code?
>>> class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__ built-in function called'
>>> s=demo()
>>> print(s)
>>> class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__ built-in function called'
>>> s=demo()
>>> print(s)
66. What will be the output of the following Python code?
class test:
def __init__(self,a="Hello World"):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()
class test:
def __init__(self,a="Hello World"):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()