python-06 abstract (function)

Chapter Six abstract # 
# 6.1 laziness is a virtue
'' '
Fibs = [0, 1]
NUM = int (the INPUT () "How MANY Fibonacci a Numbers do you want?")
For i in (NUM - 2) the Range:
fibs.append (Fibs [-2] + Fibs [-1])
Print (Fibs)
'' '
# 6.2 abstract and structure

# 6.3 custom function
# callable () determines whether an object can be called
# def fibs (num) :
# 'test'
# Result = [0,. 1]
# for I in (NUM - 2) Range:
# result.append (Result [-2] Result + [-1])
# return Result
#
# Print (Fibs ( 20))

# 6.3.1 to functions written document
# function inside the first-line string
# Print (Fibs .__ doc__)
# Print (Help (Fibs))

# 6.3.2 is actually not a function of the function

# 6.4 parameter magic
# 6.4 .1 value came from
# 6.4.2 Can I modify the parameters of it?
# Variables are local modifications, the list can be amended
# 1, why should modify parameter
# 2, if the parameter can be modified

# 6.4.3 keywords and defaults
# 6.4.4 collection parameters (front parameters *) (* collect two keywords) ** * Dictionary tuples
# DEF print_params_3 (** the params):
# Print (the params)
# print_params_3 (X =. 1, Y = 2, Z =. 3)

DEF print_params_4 (X, Y , Z =. 3, pospar *, ** keypar):
Print (X, Y, Z)
Print (pospar)
Print (keypar)
print_params_4 (. 1, 2, 2, A = 2)

# * or allocation parameter 6.4.5 * * only pass tuples or dictionaries
DEF hello_3 (Greeting = 'the Hello', name = 'World'):
Print (. '! {}, {}' the format (Greeting, name))
P = { 'name': ' Robin SIR ',' Greeting ':' Well Met '}
hello_3 (** P)

# 6.4.6 Information parameter

# 6.


scope [ 'X'] = 2
Print (X)
Print (scope [ 'X'])
# Globals global variable
DEF multiplier The (factor):
DEF multipluByFactor (Number):
Print (Number)
Print (factor)
return Number * factor
return multipluByFactor
Double = multiplier The (2)
Print (Double (. 5))


# 6.6 recursive
# 6.6.1 two classic cases: factorial power and

# 6.6.2 another classic case: binary search

'' '
Map (FUNC, SEQ [, SEQ, ...]) all elements perform functions sequence
filter (func, seq) returns a list containing its function execution result is true when all elements
reduce (func, seq [, initial ]) is equivalent to in the FUNC (FUNC (FUNC (seq [0], seq [. 1]), seq [2]), ...)
SUM (seq) seq and returns all elements
apply (func [, args [, kwargs]] ) call function (also provides parameters to be passed to the function)
'' '




Guess you like

Origin www.cnblogs.com/fuyouqiang/p/11844632.html