#_*_coding:utf-8_*_
#作者:王佃元
#日期:2019/12/21
#函数function subrouting \ procedure
#函数的意义
# 1.减少代码重复
# 2.更易扩展
# 3.保持代码一致性
# def log(log_text):
# f = open('log.txt', 'a')
# f.write('2019-10-25 15:30 %s',%log_text)
# f.close()
# print('*********function1')
# f = open('log.txt', 'a')
# f.write('2019-10-25 15:30 exec function1')
# 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()
# 函数的格式: def function_name(): 函数名区分大小写
# def show_shopping():
# print('OK')
# print(show_shopping)
# def add(a):
# print(a)
# # print(b)
# add(1, 3)
# def print_info(name, age, sex='male'): # 默认参数,设定好值,且默认参数一定放在其他参数后面
# print('%s:%d:%s'%(name, age, sex))
# # print_info('derywong',18) #必须参数
# # print_info(age = 39,name = 'derywong') #关键字参数
# print('dery', 30)
# print('wong', 35)
# print('aliex', 45, 'female')
#不定长参数 *args
# def add(*args):
# # print(args)
# sum = 0
# for i in args:
# sum += i
# print(sum)
# add(1, 2, 3, 4)
#不定长参数 **kwargs 不定长参数*args接收无命名参数,必须放在左边 **args接收有命名参数,必须放在右边
def print_info(sex = 'male', *args, **kwargs):
print(sex)
print(args)
for i in kwargs:
print('%s:%s'%(i,kwargs[i]))
print_info('dery',1,2,3,name = 'wong')
# print_info('nihoa', 18, name = 'dery', job = 'IT')
def func(name, age = 22, *args, **kwargs):