Classes for Python

Source: Internet
Author: User

1. Reflection

2. Built-in methods

__ Name __: Special method/Built-in method in class

Double Subscript Method Magic method

1.__call__

Instantiating an object ()---->> equivalent to executing the __call__ method

Application: Used to view the execution process in the source code

      

2.__len__ for viewing the length of an object

Len (object), the __len__ method that invokes object does not execute Len () if there is no __len__ error

      

3.__new__------>>> Construction method

__INIT__------>>> Initialization method

Occurs before the __init__ method is executed after instantiating the object.

1. Creating a space in memory belongs to the object

2. Pass object space to self, execute __init__

3. Returning object space to the caller

The __new__ method is executed after instantiation and then __init, which opens up a new space

Creating a singleton class with the __new__ method

Singleton class: A class that has only one instanced object from start to end

      

4.__str__ pirnt (object) can print some properties of an object directly

      

Classes for 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.