The third week of Python's object-oriented deep learning

Source: Internet
Author: User
Tags mul wrapper

Function

Name

Naming methods (official method, hump naming method)

Nomenclature: 1. Consists of numbers, underscores, and letters, and cannot begin with a number.

2. Cannot name keywords

3. Case-sensitive, uppercase is constant

Parameters

Default value

Variable parameters * args

def Say_hello (*args):    print(args)def  Main ():    '  zhangli',    Say_hello (*a_list)if__name__  '__main__':    main ()

Keyword parameter **kwargs

defSay_hello (* *Kwargs):Print(Kwargs)defMain (): A_set= {'name':'Zhangli',' Age': 24,'Sex':'female'} say_hello (**a_set)if __name__=='__main__': Main ()

Named keyword parameter *

def Foo (A, B, C, *, Name, age):    print(a+b+c)    print' : ' , age) def Main ():    foo (1, 2, 3, name='Zhang', age=24)if  __name__'__main__':    main ()

return value

Object

String

Meta-group

Collection

Nested functions

The function is called again in the higher order function function

You can write more general code by passing in functions to functions
# The second argument in the Calc function is another function, which represents a two-dollar operation
So The Calc function becomes more versatile and can be determined by the second parameter passed in.
Cohesion Poly, low-coupling high cohesion lo coupling
defCalc (my_list, op): Total=My_list[0] forIndexinchRange (1, Len (my_list)): Total=op (Total, My_list[index])return TotaldefAdd (x, y):returnX +ydefmul (x, y):returnX *ydefMain (): My_list= [1, 3, 5, 7, 9]    Print(Calc (my_list, add))Print(Calc (my_list, mul))if __name__=='__main__': Main ()

# Decorator

defrecord (FN):defWrapper (*args, * *Kwargs):Print('before you prepare to execute the%s function ...'% fn.__name__)        Print(args)Print(Kwargs)#This line of code is performing the decorated function        #We can attach additional code before and after this line of code        #This code allows us to do some extra work when we execute the function.val = fn (*args, * *Kwargs)Print('%s function execution completed'% fn.__name__)        returnValreturnwrapper#The F function is modified by the decorator, so that the F function can do more work when it is executed .@record#mergeddeff (n):ifn = = 0orn = = 1:        return1returnn * F (n-1)if __name__=='__main__':    Print(F (5))#The decorator lets us see exactly what's going on inside the function. 

Lambda function (anonymous function)--this function is very short, so shorthand, written directly in the parentheses of the parameters

Closed Package

Partial function

Currying

Scope

Local scope

Nested scopes

Global scope

Built-in scopes

Marker LEGB Local Enclose global build_in (nonlocal Global)

Classes and objects

Definition of Class

1. A class is the blueprint and template for an object, and you can define an object with a class

2. The most important of classes is data abstraction and behavioral abstraction

3. Data abstraction: Extracting common static characteristics of objects--Properties

4. Behavioral abstraction: The common behavioral characteristics of extracting objects--behavior

The relationship of the object

Use a dependency relationship (action and reaction)

Have a association (normal/aggregation/composition) (You have me, I have you)

is a inheritance relationship the process of creating a new class from an already existing class
# /< Span style= "COLOR: #808080" > base class)
# gets inherited information called subclasses (derived class /< Span style= "COLOR: #808080" > derived class)
# Span style= "COLOR: #808080" > through inheritance we can extract duplicate code from subclasses into the parent class.
# subclass by inheritance , and reuse the code to reduce the coding of the duplicate code
# In the future if you want to maintain the public code of a subclass, you only need to do it in the parent class

Seven main principles

Single principle of responsibility

Opening and closing principle

Dependency reversal principle

The principle of the Richter replacement

Interface Isolation principle

Synthetic polymerization multiplexing principle

Dimitri Law

  

The third week of Python's object-oriented deep learning

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.