Python 16th-day class instantiation

Source: Internet
Author: User

First, you first define a simple person class

1 class Person : 2     Head = 13     ear = 24     5     def  Eat (self):6         Print (' eat ')

In terms of what is a class, the definition class, the class object, the instantiation of the class, the initialization of the class is a very confusing concept for beginners.

Sometimes, it is easier to understand the more familiar concepts in our life than the new points of knowledge.

First imagine, what is human, animal, plant, bird?

Human, Xiao Ming (a specific person)

Animal class, Lion King Leo (specific one animal)

Plant type, peony (specific flower)

Bird, Woodpecker (specific one bird)


In real life, looking for an object is to find a living person.

So, the code, 1-6, defines a class named person.

Notice that the name is person,

Class person, which is defined

P1 = person ()

After executing the statement

P1 is an object of the person class, or it can be called an instance, and the concept of an object and an instance can be equated.

Execute person (), which is the instantiation of the class

The instantiation of a class can be understood as the whole process of creating an object by a class, which is done by the Python interpreter.

Instantiate this process execution ends and return the address of the instance to P1

Examples, literal understanding, real examples of existence, the key is the existence

Defining a class is a clear concept, what you can do and what you can't do. Just conceptually.

An instance (object) is created, and the instance is then called to the method in the class.

Python 16th-day class instantiation

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: 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.