Python 6 Object-oriented

Source: Internet
Author: User

Excerpt from: http://www.cnblogs.com/known/archive/2010/09/04/1818231.html

The previously mentioned operational functions and statement blocks are traditional process-oriented programming,

Typically, you write large programs that typically use object-oriented programming

Classes and objects are the main two aspects of object-oriented programming,

Class, create a new type,

Object, which is an instance of the class

Python does not have a value type and a reference type, it sees everything as a class,

class uses the class keyword to create

1. Self

Methods of a class The normal function has only one special difference ———— they must have a first parameter name outside the river,

But when you call this method you do not assign a value to this parameter, Python provides this value, and this particular variable refers to the object itself, according to the Convention its name is self

If you have a class called MyClass and an instance of this class MyObject, when you call this object's method Myobject.method (Arg1, arg2)

This is automatically converted from Python to Myclass.method (MyObject, ARGS1, arg2) ———— that's how self works.

2. Class

3. Methods

A class/object can have a function-like method, and the difference between these methods and functions is just an extra self variable.

Look at the ' self ' parameter

4. __init__ method

I have a peach. The names of many methods in a class have special significance, like __init__, which is similar to constructors.

The __init__ method runs immediately when an object in the class is set up. This method can be used to initialize your object with some of the things you want.

5. Domain

Python has two types of variables for domain classes and variables for objects

Class variables: All objects of a class are shared using only one copy of a class variable, so when an object changes the variables of a class, the change is reflected on all other instances

The variable of the object; Owned by each object, so each object has its own copy of the domain,

6. Inheritance

Python 6 Object-oriented

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.