How can you create a static variable in a Python class?
Select an option to see the answer and solution.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
67
Questions
4/4
Page
Pick an option on a question to see the right answer and solution.
Select an option to see the answer and solution.
>>> class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__ built-in function called'
>>> s=demo()
>>> print(s)Select an option to see the answer and solution.
Select an option to see the answer and solution.
class MyClass:
count = 0
def init(self):
MyClass.count += 1
obj1 = MyClass()
obj2 = MyClass()
print(obj1.count)Select an option to see the answer and solution.
>>> class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__ built-in function called'
>>> s=demo()
>>> print(s)Select an option to see the answer and solution.
class test:
def __init__(self,a="Hello World"):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()Select an option to see the answer and solution.
Select an option to see the answer and solution.