Introduction to Object-oriented meta-class (not to be continued)

Source: Internet
Author: User

tags (space delimited): Introduction to the Meta-class

Meta-Class Introduction:

Before formally introducing the meta-class, we reserve a bit of knowledge: exec;

  • The EXEC command uses
    This command has three parameters:
    1. Command in string form (extract string)
    2. Global scope; (dictionary form, if not specified, Globals () is used by default)
    3. Local scope, (in dictionary form, if default locals is not specified)
g={'x':1,'y':2}l={}exec("""global x,mx=10m=100z=3""",g,l)print(g)#print(l)
  • exec is the execution of a function; Here you remember, we'll use it back.
Everything in Python is an object, how can objects be used?

1. All can be quoted; x=obj
2.2nd, can be used as the parameters of the function of the incoming;
3. Can be used as the return value of a function
4. Can be used as a container type of element; (that is, multiple values, such as dictionaries, lists)

class Foo:#类也是对象    passobj= Foo()print(type(obj))print(type(Foo))

Execution Result:
<class main,foo>
<class ' type ' >

  • The concept of a meta-class:
    To the above example can be found: Foo is also an object, in Python everything is an object, from here can be seen: class classes, is called meta-class: <class ' type ' >


As follows: is a Chinese class defined by a meta-class:

  • Bottom line: The Meta class is the original class, which is the class class

Introduction to Object-oriented meta-class (not to be continued)

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.