【小甲鱼】零基础入门学习Python(二)函数

    技术2022-07-10  124

    function.__doc__function(a = x, b = y) 关键字参数def function(a = x, b = y): 默认值参数def function(*params) 收集参数,可输入多个参数打包为元组函数无return时返回Nonegloble 将局部变量转化为全局变量闭包 def FunX(x): def FunY(y): return x * y return FunY FunX(8)(5) def Fun1(): x = 5 def Fun2(): nonlocal x x *= x return x return Fun2() lambda 匿名函数g = lambda x : 2 * x + 1g(5)g = lambda x, y : x + yg(3, 4)

     

    filter()list(filter(None, [1, 0, False, True])) def odd(x): return x % 2 temp = range(10) show = filter(odd, temp) list(show) list(filter(lambda x : x % 2, range(10)))

     

    map 映射list(map(lambda x : x * 2, range(10)))

     

    递归import syssys.setrecursionlimit(n)
    Processed: 0.010, SQL: 9