Python 中的函数

 

函数的定义

lanmda函数

函数的引用(有参数和无参数)

参数的默认值

关键字参数,及顺序(非关键字参数要在关键字参数之前使用)

递归 1. 反复调用自己

        2. 必须有边界条件,即停止递归的条件

        回归 + 递推

递归与循环的比较

        递归的代码更简洁、更符合自然逻辑、更容易理解

递归的效率: 资源消耗比循环大

 

 def foo(arg1, *args):
     print("Type arg1 is {}, value: {}".format(type(arg1), arg1))
     print("Type of args is {}, value: {}".format(type(args), args))

foo("arg1", "arg2", "arg3")
Type arg1 is <type 'str'>, value: arg1
Type of args is <type 'tuple'>, value: ('arg2', 'arg3')

    

 

posted on 2019-07-31 23:52  ShannonHan  阅读(191)  评论(0编辑  收藏  举报