day-9

#coding = Unicode
#函数式编程


#函数
#def funcl():       #定义函数
#    """testing1"""
#    print('in the func1')
#    return()
##过程(没有返回值的函数)
#def func2():
#    '''testing2'''
#    print('in the func2')


#x = funcl()
#y = func2()
#print("from func1 return is %s" %x)
#print("from func2 return is %s" %y)
#import time
#def logger():
#    #time_format = '%Y-%m-%d %X'
#    times = time.strftime(format['%Y-%m-%d %X',t])
#with open('yesterday2','a') as f:
#        f.write = ('%s end action\n'  %times)
        
#def test1():
#    print('in the test1')
#    logger()
#def test2():
#    print('in the test2')
#    logger()
#def test3():
#    print('in the test3')
#    logger()
#def test1():
#    print('in the test1')
#    return test1
#def test2():
#    print('in the test2')
#    return 0
#def test3():
#    print('in the test3')
#    return 1,'hello',['tom','lily'],{'name':'kali'}
#    #return 0    #renturn返回值(可以返回多个值)
#x = test1()
#y = test2()
#z = test3()
#print(x)
#print(y)
#print(z)


#def test(x,y,z):  #形参
#    print(x)
#    print(y)
#    print(z)
##test(1,2)      #实参与形参一一对应
#test(1,2,z=3)   #关键参数不能写到位置参数前面


#def test(x,y=2):    
#    '''默认参数的特点:调用函数的时候,默认参数可有可无
#       用途:默认值'''
#    print(x)
#    print(y)
#test(1,3)


#参数组以*开头,可以接受多个实参,转换成元组
#接收N个位置参数,转换成元组
#def test(*args):    
#    print(args)
#test(*[1,2,3,4,5,6])


#def test1(x,*args):
#    print(x)
#    print(args)
#test1(1,2,3,4,5)


 #**kwargs:把N个关键字参数,转换成字典方式
#def test2(**kwargs): 
#    print(kwargs)
#    print(kwargs['name'])
#    print(kwargs['age'])
#test2(name='tom',age=12,sex='F')
#test2(**{'name':'tom','age':8})


#def test3(name,**kwargs):
#    print(name)
#    print(kwargs)
#test3('tom')


#def test4(name,age=8,**kwargs):
#    print(name)
#    print(age)
#    print(kwargs)
#test4('tom',sex='m',hobby='tesla',age=5)


#def test4(name,age=8,*args,**kwargs):
#    print(name)
#    print(age)
#    print(args)
#    print(kwargs)
    
#def logger(source):
#    print("from %s" % source)
#    logger("test2")
#test4('tom',sex='m',hobby='tesla',age=5)


#局部变量只在函数里生效,
#def change_name(name):
#    print("lily",name)
#    name ='jack'        #这个函数就是这个变量的作用域
#    print("kali",name)


#name = "tom"
#change_name(name)
#print(name)


#school = "edu"
#def change_name(name):
#    global school       #global用于声明局部变量为全局变量
#    print("lily",name)
#    name ='jack'        #这个函数就是这个变量的作用域
#    school = 'linux'
#    print("kali",name)
#    print(school)
#name = "tom"
#change_name(name)
#print(name)
#print(school)


#不要在函数内部定义全局变量,容易产生混乱
#def change_name():      
#    global name
#    name = "tom"
#change_name()
#print(name)


#列表、字典、集合、类局部可以改全局
#字符串和整数无法局部改全局
#names = ["tom","lily"]
#def change_name():      
#    print(names)
#    names[0] = "kali"
#    print(names)
#change_name()
#print(names)


#递归函数
#def calc(n):
#    print(n)
#    if int(n/2) > 0:
#        return calc(int(n/2))
#    print("->",n)
#calc(10)


#高阶函数
#def add(a,b,f):
#    return f(a)+f(b)
#res = add(3,-6,abs)
#print(res)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值