Function definitions and usage * args ** kwargs mass participation Usage

= 2 * X + Y. 1 
X =. 3
Y->. 7
X =. 3
Y->. 7
'' '
# Test DEF (X):
#' ''
#. 1 + 2 * X
#: X param: shaping digital
#: return: the computed results back
# '' '
# Y = 2 * X +. 1
# return Y
#
# DEF Test ():
#' ''
# 2 * X +. 1
#: param X: shaping digital
#: return: Back calculation results
# '' '
# X =. 3
# Y = 2 * X +. 1
# return Y
# a = Test ()
# Print (a)

# procedure: that is not a function that returns value


# DEF Test01 ():
# MSG =' Test01 '
# Print (MSG)
#
#
# DEF Test02 ():
# = MSG' Test02 '
# print(msg)
# return msg
#
# def test03():
# msg = 'test03'
# print(msg)
# return 1,2,3,4,'a',['alex'],{'name':'alex'},None
#
# def test04():
# msg = 'test03'
# print(msg)
# return {'name':'alex'}
# t1=test01()
# t2=test02()
# t3=test03()
# t4=test04()
# print(t1)
# print(t2)
# print(t3)
# print(t4)







# def calc(x,y): #x=2,y=3
# res=x**y
# return x
# return y
# res=calc(2,3)
# # print(x)
# # print(y)
# print(res)
# # a=10
# # b=10
# # calc(a,b)


DEF Test # (X, Y, Z): X = #. 1, Y = 2, Z =. 3
# Print (X)
# Print (Y)
# Print (Z)

# positional parameters must correspond, one can not a plurality nor
# Test (l, 2,3)

# keyword parameter correspondence need, not a lack of a multiple nor
# Test (Y =. 1, X =. 3, Z =. 4)

# parameters must be in a position keyword left argument
# test (1, y = 2,3 ) # error
# test (1,3, y = 2 ) # error
# Test (l, 3, Z = 2)
# Test (l, 3, Z = 2, y = 4) # error
# test (z = 2,1,3) # error

# DEF handle (X, type = 'MySQL'):
# Print (X)
# Print (type)
# handle ( 'Hello' )
# handle ( 'Hello', type = 'SQLite')
# handle ( 'Hello', 'SQLite')

# the install DEF (func1 = False, True = func2, func3 = True):
# Pass

# parameters: ** * Dictionary list
DEF the Test (the X-, * args):
Print (the X-)
Print (args)


Test # (. 1)
# Test (1,2,3,4,5)
# Test (. 1, { 'name': 'Alex'})
# Test (. 1, [ 'X', 'Y', 'Z' ])
# Test (. 1, * [ 'X', 'Y', 'Z'])
# Test (. 1, * ( 'X', 'Y', 'Z'))

# Test DEF (X, ** kwargs):
# Print (X)
# Print (kwargs)
# Test (. 1, Y = 2, Z =. 3)
# Test (1,1,2,2,2,2,2, Y = 2, Z =. 3 )
# Test (. 1, Y = 2, Z =. 3, Z =. 3) # being given: two can not pass a parameter value

DEF Test (X, * args, ** kwargs):
Print (X)
Print (args, args [-1])
Print (kwargs, kwargs.get ( 'Y'))
# Test (1,1,2,1,1,11,1, X =. 1, Y = 2, Z =. 3) given #
Test # (1,1,2,1,1,11,1, Y = 2, Z =. 3)

# Test (. 1, * [l, 2,3], ** { 'Y':}. 1)

Guess you like

Origin www.cnblogs.com/xiaomahei/p/12056512.html