Knowee
Questions
Features
Study Tools

What will be the output of below Python code?class A():    def __init__(self,count=100):        self.count=countobj1=A()obj2=A(102)print(obj1.count)print(obj2.count)100100100102102102ErrorClear ResponseSave & Next

Question

What will be the output of below Python code?class A():    def init(self,count=100):        self.count=countobj1=A()obj2=A(102)print(obj1.count)print(obj2.count)100100100102102102ErrorClear ResponseSave & Next

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the Python code will be:

100 102

Explanation:

The class A is defined with an initializer method (init) that takes one argument 'count' with a default value of 100.

When obj1 is created without any argument, the default value 100 is used for 'count'. Therefore, when we print obj1.count, it outputs 100.

When obj2 is created with an argument 102, this value overrides the default value of 'count'. Therefore, when we print obj2.count, it outputs 102.

This problem has been solved

Similar Questions

What will be the output of below Python code?class A():    def __init__(self,count=100):        self.count=countobj1=A()obj2=A(102)print(obj1.count)print(obj2.count)100100100102102102Error

Which of the following is correct?class A:    def __init__(self):        self.count=5        self.count=count+1a=A()print(a.count)560ErrorClear ResponseSave & Submit

What will be the output of the following Python code?class Demo: def __init__(self): self.a = 1 self.__b = 1 def get(self): return self.__bobj = Demo()obj.a=45print(obj.a)

What will be the output of the following Python code?(i) class A: (2)def __init__(self,x):self.x = xdef count(self,x):self.x = self.x+1class B(A):def __init__(self, y=0):A.__init__(self, 3)self.y = ydef count(self):self.y += 1def main():obj = B()obj.count(

What will be the output of the following code?class MyClass:    def __init__(self, value=5):        self.value = valueobj1 = MyClass()obj2 = MyClass(10)print(obj1.value, obj2.value)

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.