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)100100100102102102Error

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)100100100102102102Error

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

Solution 1

The output of the Python code will be:

100 102

Explanation:

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

  2. An object 'obj1' is created from class A without passing any argument, so 'count' will take the default value 100.

  3. Another object 'obj2' is created from class A with an argument 102, so 'count' will take the value 102.

  4. When we print 'count' for 'obj1', it will print 100.

  5. When we print 'count' for 'obj2', it will print 102.

This problem has been solved

Solution 2

The output of the Python code will be:

100 102

Explanation:

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

  2. An instance of class A, obj1, is created without providing a value for 'count'. Therefore, the default value of 100 is used.

  3. Another instance of class A, obj2, is created, this time with a value of 102 provided for 'count'.

  4. When the 'count' attribute of obj1 is printed, the output is 100.

  5. When the 'count' attribute of obj2 is printed, the output is 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)100100100102102102ErrorClear ResponseSave & Next

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)5 1010 50 10None None

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

what is the output of following python code? class myclass:    def __init__(self,a):        self.a = a        print(self.a)o=myclass()

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.