class fruits: def __init__(self): self.price = 100 self.__bags = 5 def display(self): print(self.__bags)obj=fruits()obj.display()
Question
Solution 1
The given code is written in Python and it defines a class named fruits
. Here's a step-by-step explanation of the code:
-
class fruits:
This line is defining a class namedfruits
. -
def __init__(self):
This line is defining the constructor method for the class. The__init__
method is c Knowee AI is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI
Similar Questions
class Student: def __init__(self,name,id): self.name=name self.id=id print(self.id)std=Student("Simon",1)std.id=2print(std.id)
what is the output of following python code? class myclass: def __init__(self,a): self.a = a print(self.a)o=myclass()
class Demo: def __init__(self): self.a = 1 self.__b = 1 def get(self): return self.__bobj = Demo()obj.a=45print(obj.a)
Which of the following is correct?class A: def __init__(self,name): self.name=namea1=A("john")a2=A("john")
class Dog:def __init__(self):# missing line hered = Dog()print(d.age)Fill in the missing line of code, so that the output for this code is 5.
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.