Python Object-oriented two

Source: Internet
Author: User

Communicate the pipeline through this method

Log module Logging Python is available separately

Re.split (Rules, strings, 1) are split with the first conforming rule.

Random module

Converts a number to a letter char (+) = A

__INIT__: Constructs a method that executes when instantiated

Classic class:

such as: Class N:

Pass

New class:

such as: Class M (object):

Pass

A class that inherits either directly or indirectly from the object class is a new class. Recommended use of modern class


The difference between the two:

Inheritance: Java, C # does not support multiple inheritance, Python supports multiple inheritance

Classic class, Depth first find

New class: Breadth First search

Class contains: Methods, fields, and properties

Property: attribute is defined with an adorner property at the top, without parentheses at execution, to forge a method into a field

The attributes in the new class can be preceded by the @ method. Setter and @ method. deleter

Normal fields: for example, Self.name

Static fields: For example, write in class. Class F:

name = ' Erric ' #静态字段

Use the class name for static fields. Field Call

Use objects for normal fields. Field Call

Normal method:self-> object, object invocation, parameter, at least one self

Class method: Using Adorner Classmethod

Such as:

@classmethod

There can be only one parameter CLS, which is a class call, which can be called directly using the class call method without creating the object directly with the class.

static method: Using Adorner @staticmethod

Parameters can be arbitrary, is a class call, you can directly use the class call method without creating the object, directly with the class call.

Python modifier, private and public, private only within their own to use, public anywhere can be called.

A private object can be accessed and requires an object. _ Class __ Members

Python encapsulation

1, multiple methods common a set of variables, variables encapsulated into the object

2. Create multiple methods with one template.

Python inheritance

1. Base class, derived class

2. Multiple inheritance

3. New type, Classic class

4, classic class depth first, new type breadth priority--interview with

Class, object, Memory graph

Class Member

1. Fields

Normal field

Static fields

2. Methods

Common method: Trigger: Object at least one self,self = current object

Class method: Trigger: Class has only one CLS CLS = Current class

static method: Trigger: Class arbitrary parameter

3, attributes (variant of the method, the access is similar to the field does not need parentheses)

Access method:

Method One: @property

Method Two: Data = Property (method name)

Obj. Data = Executes the method and gets the return value of the method

Properties in the new class

@property

@ Method name. Setter

@ Method name. deleter

Class member Modifiers:

Public, private

Private front plus two underline, only internal access, no other place access

If you do not want to access the private property, you need the object. _ Class __ Members

__CALL__:

Object (), execute the Call method

__DICT__:

View members within a class or object

__STR__:

If the __str__ method is defined in a class, the return value of the method is output by default when the object is printed.


This article is from the "Python" blog, so be sure to keep this source http://dzlly1.blog.51cto.com/932657/1722261

Python Object-oriented two

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.