class definition and instantiation of Python

Source: Internet
Author: User

Understanding class Properties and Instance properties:

Variables defined directly within a class are called Class properties, class properties are public, each class instantiation automatically owns the properties of the class, and the initial address of this property of the instantiated object points to the address of the class attribute

If you assign a value directly to a property of an instantiated object, this changes the memory address of the property, and instead of pointing to the Class property address, it opens a space in the instance memory address to save the property

The self.xx defined within a class method are instance properties, are private, each instance has its own storage space, and the individual private properties exist in their own space

Of course, you can also add properties directly to an instantiated object, such as A1 is an instantiated object of animal, then A1.age = 18 Adds a class property to A1, but other instantiated objects of animal do not have an age property

class definition and instantiation of Python

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.