πŸ“Š Python
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
πŸ’¬ Discuss
βœ… 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.

Explanation by: Rajeev Malhotra
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
189
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Rajeev Malhotra
Publisher
πŸ“ˆ
82%
Success Rate