‘‘‘
Functional programming for encapsulating programming
Default parameters are typically placed on the last side
The default parameter can have more than one, the value of the default parameter can also be changed
The default parameter needs to be assigned a value
The order of the parameters can also be not in order
A * that converts all the parameters into a single tuple
2 *, will convert all the parameters into a dictionary
One * in front, two * in the back
‘‘‘
Def show (A, B):
Print (A, B)
Show (b=123,a=456)
Def Sho (a):
Print (A,type (a))
n=[1,2,3,4]
p={' K1 ': +, ' K2 ': 33}
Sho (n)
def sh (*args):
Print (Args,type (args))
SH (n)
def s (A,**kwargs):
Print ("Can", Kwargs,type (Kwargs))
Print (a)
S (45,n1=78,uu=123,bb=99)
S (45,**p)
def m (*args,**kwargs):
Print (Args,type (args))
Print (Kwargs,type (Kwargs))
M (n,t=67,y=89)
‘‘‘
This way the n,p will be put in the args, change
‘‘‘
M (n,p)
"""
As shown below for solution
"""
M (*n,**p)
S= "{0}{1}"
Ret=s.format (' Alex ', ' B ')
l=[' Alex ', ' B ']
Print (ret)
Ret1=s.format (*L)
Print (' Chognxin ', Ret1)
d={' K1 ': 1, ' Ke ': 2}
Print (d)
"""
Lambda, a simple way to define a function
The first A is a formal parameter, which can be more than one parameter, followed by:, followed by the execution body.
Lambda will do two things, first, create formal parameters, and return the contents of the second function,
Lambda can only write a single line, so it is only suitable for writing simple functions
"""
Func=lambda a:a+1
Print (func (99))
C:\Python34\python.exe c:/users/admin/pycharmprojects/untitled1/zidian/can name tuples/functions. py
456 123
[1, 2, 3, 4] <class ' list ' >
([1, 2, 3, 4],) <class ' tuple ' >
can {' N1 ': +, ' BB ':, ' UU ': 123} <class ' Dict ' >
45
can {' K2 ': ' K1 ': <class ' dict ' >
45
([1, 2, 3, 4],) <class ' tuple ' >
{' Y ': <class, ' t ': Dict ' >
([1, 2, 3, 4], {' K2 ':, ' K1 ':] <class ' tuple ' >
{} <class ' dict ' >
(1, 2, 3, 4) <class ' tuple ' >
{' K2 ': ' K1 ': <class ' dict ' >
Alexb
Chognxin Alexb
{' Ke ': 2, ' K1 ': 1}
100
Process finished with exit code 0
python| function