Python class and Object Features, python Object Features

Source: Internet
Author: User

Python class and Object Features, python Object Features

I will share some basic knowledge about the python class. I believe that you have a certain understanding of python. The python class mentioned today is suitable for those who are engaged in long-term product development.

Compared with other languages such as C ++ and JAVA, python oop is easier to understand and use. It removes some complex syntax features.

When you get started with the python class, you can think of it as a tree, trunk = parent class, and root = subclass.

The roots absorb the nutrition of the trunk, and can absorb the nutrition of several trunk at the same time. Therefore, python can carry out multi-inheritance and rewrite the attributes and methods of the parent class.

Class Person ():
Def _ init _ (self, name ):
Self. name = name

Def say (self): # object Method
Print self. name

Def _ notsay (self): # private Method
Print self. name

User = Person ('xiaoming ')
User. say ()
User. _ say ()


The above is a simple class definition, __init _ (). This is a class constructor. It is called when an object is generated. Other languages also have similar constructor methods.

Python has a garbage collection mechanism, so you do not need to define the destructor.

Related Article

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.