"Python" "Some concepts and comparisons"

Source: Internet
Author: User

TYPE.__NEW__ (): Returns the class. You can think of a class as an instance created by Metaclass.

__new__ () in the normal class: Returns an instance of the class.

__NEW__ (): Returns an instance of the class. The Python interpreter executes automatically.

__INIT__ (): You have to have an instance before you can call this method.

Type.__new__ (cls,name,bases,attrs): Cls-> class,name-> class name, Bases-> inherited class consists of a tuple, a member of the Attrs-> class, contains member variables and member methods, and so on.

type(‘Hello‘, (object,), dict(hello=fn)): 第一个参数:class名字, 第二个参数:继承的父类集合,注意Python支持多重继承,如果只有一个父类,别忘了tuple的单元素写法

The third parameter: class's method name and function binding, where we bind the function fn to the method hello name

"Python" "Some concepts and comparisons"

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.