A

Admin • 833K Points
Coach

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
  • (A) 20
  • (B) 10
  • (C) None
  • (D) Error
  • Correct Answer - Option(B)
  • Views: 29
  • Filed under category Python
  • Hashtags:

Explanation by: Admin

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.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.