Which of the following is correct?class A: def __init__(self): self.count=5 self.count=count+1a=A()print(a.count)
Question
Solution 1
The code you provided is incorrect. Here's why:
class A:
def __init__(self):
self.count=5
self.count=count+1
a=A()
print(a.count)
In the __init__
method, you are trying to increment self.count
by count
, but count
is not defined anywhere in the scope of
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study prob
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solv
Similar Questions
Which of the following is correct?class A: def __init__(self): self.count=5 self.count=count+1a=A()print(a.count)
Which of the following is correct?class A: def __init__(self): self.count=5 self.count=count+1a=A()print(a.count)560Error
Which of the following is correct?class A: def __init__(self): self.count=5 self.count=count+1a=A()print(a.count)560Error
class fruits: def __init__(self): self.price = 100 self.__bags = 5 def display(self): print(self.__bags)obj=fruits()obj.display()
Which of the following is correct?class A: def __init__(self,name): self.name=namea1=A("john")a2=A("john")