The Day8 of Python

Source: Internet
Author: User

One, homework

Points
1 encapsulation, objects nested within objects
2 Pickle,load: Remember, be sure to import related classes


Two previous sections Review and supplement


Object-Oriented Basics:
1 relationship of classes and objects
23 Major features:
Packaging
Inherited
Object-oriented three major features:
3 polymorphic
def func (ARG):
Print (ARG)
Func (1)
Func (' Alex ')
Func ([11,22,33])

C#/java
def func (int arg):
Print (ARG)
Func (123)
Func ("Alex") #报错
Look at the picture


Three members in object-oriented


Field
Static fields
Normal field
PS: Static field code is loaded when it has been created
Class Foo:
#字段 (static field)
CC = 123
def __init__ (self):
#字段 (normal field) stored in the object
Self.name = ' Alex '

Def show (self):
Print (Self.name)

#一般情况: Access your own fields
#规则:
#普通字段只能对象访问
#静态字段用类访问 (Access is available when last resort)

Method
All methods belong to the class
Normal method, called by the object to execute (method belongs to class) at least one self
static method, the parameter is optional above add a @staticmethod can be executed by the class call (no need to use the object to call)
Class method, the special form of a static method must have the parameter CLS--"represents the class name

Property
A nondescript thing.
A form of writing with a method, with a field access form

Four member modifiers

Five Special members


__init__
__doc__
__call__
__setitem__

Six object-oriented others:

-Isinstance
-Issubclass
-Inheritance 2.7
Application
Custom types, supplementing dictionaries, ordered dictionaries
Extension of the source code

Seven Exception handling:

A single case model of eight design patterns

Class method
Static methods

The Day8 of Python

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