Python little Exercise--Properties

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.