Select an option to see the answer and solution.
Classes and Objects in Python
practice.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
67
Questions
3/4
Page
Pick an option on a question to see the right answer and solution.
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()Select an option to see the answer and solution.
Select an option to see the answer and solution.
class test:
def __init__(self,a):
self.a=a
def display(self):
print(self.a)
obj=test()
obj.display()Select an option to see the answer and solution.
class Demo:
def __init__(self):
pass
def test(self):
print(__name__)
obj = Demo()
obj.test()Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
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)Select an option to see the answer and solution.
Select an option to see the answer and solution.
class test:
def __init__(self):
self.variable = 'Old'
self.Change(self.variable)
def Change(self, var):
var = 'New'
obj=test()
print(obj.variable)Select an option to see the answer and solution.
>>> class A:
def __init__(self,b):
self.b=b
def display(self):
print(self.b)
>>> obj=A("Hello")
>>> del objSelect an option to see the answer and solution.
Select an option to see the answer and solution.
class fruits:
def __init__(self, price):
self.price = price
obj=fruits(50)
obj.quantity=10
obj.bags=2
print(obj.quantity+len(obj.__dict__))Select an option to see the answer and solution.
Select an option to see the answer and solution.
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(student.__doc__)Select an option to see the answer and solution.
class Parent:
x = 10
class Child(Parent):
pass
obj = Child()
print(obj.x)Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.