第六章、抽象

第六章、抽象 (函数式编程)

  6.1  懒惰是一种美德(就是说明为了减少代码量,提高代码的可用性)

  6.3  自定义函数

  函数是结构化编程的核心。关于函数定义,举个简单的例子就行:

def hello(name):
    print('hello,world')
def fib(num):
    result=[0,1]
    for i in range(num-2):
        result.append(result[-2]+result[-1])
    return  result
hello('Alex')
print(fib(10))

  从而,结果为:

hello,world
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

  6.3.1  给函数编写文档

  记住编写函数的文档,有两种方式,第一种用#,第二种,用“”编写即可

 

猜你喜欢

转载自www.cnblogs.com/liuxinkai94/p/10799384.html