Python feature note (1): python feature note

Source: Internet
Author: User

Python feature note (1): python feature note

1. constructor and destructor

1. python has constructor and destructor, which are the same as other languages. If the subclass needs to use the constructor of the parent class, it needs to be explicitly called in the constructor of the subclass. If the subclass has its own constructor, the constructor of the parent class is not automatically called. However, for sub-classes without constructors, the constructor of the parent class is automatically inherited, by default, child classes inherit the constructor of the first parent class of multiple parent classes. Note: Generally, the subclass should inherit all attributes and methods of the parent class. You can understand the constructor In the subclass as overwrite the constructor of the parent class.

2. The Destructor is called only when del is called, just like other speech. Display call

 

Ii. Heavy Load and coverage

Python does not have the concept of overload. You cannot use multiple functions with the same name as a class to implement overload based on the number of parameters or different parameter names. In python, functions with the same name always overwrite the previous function by default, which is not convenient, but it increases readability and comprehensibility. I think python is not overloaded because python is a dynamic language. Since the parameters are only determined at runtime, the overload should be meaningless for python; second, python does not allow missing parameters, which makes overloading meaningless for python. Note: in c #, you can write a virtual method in the parent class, and then use override in the subclass to reload the method. when calling the virtual method, the overwritten method is actually called.

 

Iii. Language type

There is no doubt that python is a dynamic strong-type language. If it is static, all I have seen is static in the list. The value passes a value (a new memory value is assigned), and the pointer passes a pointer to the memory, which is easy to understand.

 

Iv. Polymorphism

In simple terms, polymorphism is the multiple forms or States of a class. Python does not support polymorphism. Generally, subclasses are used to inherit the parent class and re-function. This is actually another object.

 

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.