function Function - function definitions and parameters

_ * _ Coding #: UTF-8 _ * _ 
# Author: Wang Dian-yuan
# Date: 2019/12/21
# subrouting function function \ Procedure
# function meaning
# 1. reduce code duplication
# 2 more scalable
# 3. Keep the code consistency
DEF log # (log_text):
# = F Open ( 'log.txt', 'A')
# f.write ( '% S 2019-10-25 15:30', log_text%)
# f.close ()
# Print ( '*************************************** function1')
# = F Open ( 'log.txt', 'A')
# f.write ( 'Exec function1 2019-10-25 15:30')
# F .close ()
#
# Print ( '*************************************** function2')
# = F Open ( 'log.txt', 'A')
# f.write ( 'Exec function2')
# f.close ()
#
# Print ( '*************************************** Function3')
# = F Open ( 'log.txt', 'a')
# f.write('exec function3')
# F.close ()

format # function: def function_name (): function names are case sensitive
# DEF show_shopping ():
# Print ( 'the OK')
# Print (show_shopping)

# DEF the Add (A):
# Print (A )
# # print (B)
# the Add (. 1,. 3)

# DEF print_info (name, Age, Sex = 'MALE'): # default parameter value set up, the default parameters and the other parameters constant on the back
# print ( '% S:% D: S%'% (name, Age, Sex))
# # print_info ( 'derywong', 18 is) must parameter #
# # print_info (age = 39, name = 'derywong') # keyword parameter
# Print ( 'Dery', 30)
# Print ( 'Wong', 35)
# Print ( 'aliex', 45, 'FEMALE')

# variable length parameter * args
# DEF the Add (* args):
# # Print (args )
# = SUM 0
# for i in args:
# sum += i
Print # (SUM)
# the Add (. 1, 2,. 3,. 4)

# ** kwargs variable length parameter variable length * args parameter received no named parameters, on the left must have received ** args named parameters, must be placed on the right
def print_info (Sex = 'MALE', * args, ** kwargs):
Print (Sex)
Print (args)
for I in kwargs:
Print ( '% S:% S'% (I, kwargs [I]))
print_info ( 'Dery', l, 2,3, name = 'Wong')
# print_info ( 'nihoa', 18 is, name = 'Dery', Job = 'the IT')

DEF FUNC (name, Age = 22 is, args *, * * kwargs):

Guess you like

Origin www.cnblogs.com/python-beginner/p/12078703.html