The 4th Lesson of "Julyedu-python Foundation": Object-oriented Foundation

Source: Internet
Author: User

Class: A collection of objects that describe an object with the same properties and methods, which defines the properties and methods that are common to each object in the collection. An object is an instance of a class.

Object: an instance of a data structure defined by a class. Object consists of two data members (class variables and instance variables) and methods

Class variables: Class variables are common throughout the instantiated object. Class variables are defined in the class and outside the body of the function. Class variables are not typically used as instance variables

Instance variable: A variable defined in a method that only acts on the class of the current instance.

Use of "classes" and "objects":

A class is a template that can contain multiple functions and functions in a template.

Objects are instances created from templates that can execute functions in a class through an instance object

# Create a class class Foo:    # function in class def  Bar (self):        # function Description        pass # --------finished-------- # Create object from fooobj = foo ()# When creating an object, remember to add a parenthesis

Note that the class is represented as a hump (HelloWorld) According to the Python general rules

And the other obj, and so on, are separated by ' _ ' (this_is_object)

function in a class The first argument must be self, and the function defined in the class is called the "method"

The 4th Lesson of "Julyedu-python Foundation": Object-oriented Foundation

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.