Week - 14 Functional Programming Section -Python3.5-

PCJ # 
# Functions
DEF funct1 ():
'' 'the this IS funct1' ''
Print ( "in The funct1")
return 0 #return function indicates the end of the return value

# None Return Value i.e. during the process can be expressed as, that process. function returns no value
DEF funct2 ():
'' 'the this iS funct2' ''
Print ( "in the funct2")


# call:
funct1 ()
funct2 ()
X = funct1 () # X, represents a return to funct1 value
y = funct2 () # returns none
Print ( "% S reture funct1 IS" X%) returns a value # 0
Print ( "% S funct2 IS reture"% Y) returns a value of # none
Print ( "---- -------------- I was the dividing line -------------------------------- --------------- ")
DEF test01 ():
Pass

DEF Test02 ():
return 0

def test03():
return 0,10,"hello",{1,2},("pcj")

Test01 = T1 ()
T2 = Test02 ()
T3 = TEST03 ()
Print (T1) # summary: Returns none
Print (T2) # summary: Returns Object
Print (T3) # Summary: return value tuple
Print ( "I am the dividing line --------------------------- ------------------ -------------------- ")
# with a function parameter
def test (x, y): # xy for the parameter, the parameter in the form of
Print (X)
Print ( Y)

Test (1,2) 1,2 # as the argument that is passed on the upper surface 12, respectively, in the xy argument, actually exists (location call)
Test (Y = 2, X =. 1) may be called with # , location may be different. Do not control sequence (call key)


# default parameters
def f1 (x, y = 2 ): # This is called the default parameters
Print (X)
Print (Y)
F1 (. 1, Y = 10) # Of course, there may also be Y re-assignment
# default parameters features:
# when calling the function, the default parameters can not pass pass
# purposes: as installing software, there will be some default options. Or the port number of the database. The default male. And so much

more # pass parameters Parameter sets]
def test (* args): # * on said received parameter I is not fixed, args parameter receiving a plurality of positions, is converted to a tuple
Print (args)

Test (1,2,3,4,5) # receiving after becoming a tuple store
print ( "------------------ ---------------- I'm a dividing line ------------------------------- ")
# combination
DEF test1 (the X-, * args):
Print (the X-)
Print (args)
(1,2,3,4,5) # result is test1, 1 x 2345 to args
Print ( "I am the dividing line ------------------ ----------------------------------------------- ")
# the N-th keyword dictionary passes parameters to change the way
DEF test2 (** kwargs):
Print (kwargs)
test2 (name = "PCJ", 22 is = Age, Sex = "M")
# and a binding position parameter
def f2 ( name, kwargs **):
Print (name)
Print (kwargs)
F2 ( "PCJ", 18 is = Age, Sex = "M")

Guess you like

Origin www.cnblogs.com/pcjbk/p/10987855.html