Q. What is the output of the following code?
Code:
class MyClass:
def __init__(self, id):
self.id = id
id = 20
o = MyClass(10)
print o.id
β
Correct Answer: (B)
10
Explanation: Instantiating the “MyClass” class automatically calls the __init__ method and passes the object as the self parameter. 10 is assigned to the data attribute of the object called id.