Arrow This job:
1 classBox:#define a class named box, the class name does not have parentheses, the class contains class properties and class methods, and the class does not define class properties2 " "This is a class that calculates the volume" "#This is the __doc__ property of this class, and after executing the class, you can enter box.__doc__ in the interactive interface to view this line of explanatory text.3 def __init__(self):#This is the constructor of a class that automatically calls this __init__ method when the box is instantiated4self.length=0.0#This is an instance property that is accessed within the class with Self.length, outside of the class using the instance name. Length5self.width=0.06self.height=0.07Self.__valum=0.0#A variable at the beginning of a double-line change represents a private variable, so he is a private instance property and can only be accessed within the class8 defComputevalum (self):#defines a class method. 9Self.__valum=self.length*self.width*Self.heightTen Print('length =', Self.length,'width =', Self.width,'height =', Self.height,'valum=', self.__valum) OneComputa=box ()#Instantiate the box class AComputa.length=1 -computa.width=2 -Computa.height=3 the Computa.computevalum () - -Computb=box ()#Instantiate the box class -computb.length=2 +computb.width=2 -Computb.height=3 +Computb.computevalum ()
I only instantiated two times.
Results:
Python little Exercise--Properties