Python features small note (i)

Source: Internet
Author: User

I. About constructors and destructors

1, Python has constructors and destructors, and other languages are the same. If the subclass needs to use the constructor of the parent class, it needs to be explicitly called in the constructor of the subclass, and if the subclass has its own constructor, the constructor of the parent class is not automatically called, but for subclasses without constructors, the constructor of the parent class is automatically inherited. And subclasses will always inherit the constructor of the first parent class in more than one parent class by default. Note: In general, subclasses should inherit all the properties and methods of the parent class, and the constructor method in the subclass can be understood as overriding the constructor method that overrides the parent class.

2. Destructors, like other sounds, are called when Del is called. The call should be displayed

Ii. about overloading and covering

There is no concept of overloading in Python, and multiple functions with the same name as the class cannot be overloaded by the number of arguments or by different implementations of parameter names. Python, a function of the same name, always overrides the previous function by default, which is inconvenient, but adds readability to rigor. I think Python is not overloaded, because Python is a dynamic type of language, since parameters are determined only at run time, that overload is meaningless for python, and Python does not allow missing parameters, which makes overloading meaningless for python. Note: In C #, you can write a virtual method in a parent class, and then overload the method with override in a subclass, and when you call a virtual mode, the overridden method is actually called.

Iii. type of language

There is no doubt that Python is a dynamic, strongly typed language, and if static, the only thing I have seen is static in the list. Value passing is a value (given a value of new memory), and pointer passing is a pointer to memory, which is well understood.

Iv. about polymorphic

In simple terms, polymorphism is the representation or state of a class. Python does not support polymorphism, and the subclass inherits the parent-class re-function, which is actually another object.

Python features small note (i)

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.