Python Learning notes--Qi

Source: Internet
Author: User

1. polymorphic

2. Static methods

3. Class methods

4. Attribute methods

5. The origin of the class

6. Reflection

7. Exception Handling

8.Socket Communication

When the class needs to inherit two, and the arguments for each class are different

you need to inherit one of the classes (for example:person) in the following way, passing arguments

call the method of the parent class . Person. Method Name

polymorphic Example

Multiple implementations of an interface

Static methods

@staticmethod

The class is no longer related to the class and cannot be called by Self. It's not necessary for self to write.

the only connection to the class is when the call is class to invoke the

Use For example :OS Toolkit

Class method

Property method

@property into a property call the direct method name does not add (), like a variable called

@eat. When the setter becomes a property call, it is impossible to pass arguments, which can be used to pass parameters in

into the d.eat= "QQQ" parameter, feeling similar to the Java overload,

Called when the value is assigned . there are @eat. Setter of the

@eat. Deleter Delete Properties

Two methods

Output results

in the class __call __ Method, you can trigger execution after the object ()

as follows:D is an object, plus () call will error, but add this method, you can call.

The __call __ method is performed .

Output

__dict__ View all members of a class or object

Use scenario: View, class, or instance properties after a project has been running for a period of time

When you print an instance, a string of memory addresses is normally output , and after you add this method to the class

You can return the results you want.

as follows: return the name parameter of the object

To manipulate objects like a dictionary

The second way to create a class

Type is the top class

First write the constructor, and then use the type to load these things in.

The origin of the class

The __new__ method is executed before the __init__ method is executed, and is a intit method called by the new method

Python Learning notes--Qi

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.