Lecture 1 Intro

Lecture 2 Function

  • 函数签名Function signature
image-20220430112729904
  • 函数体Function body

    image-20220430113537980
  • Frame

    scope-作用域

    frame-栈帧

    • 表示程序运行时函数调用栈

Lecture 3 Control & Iteration

lamda 匿名函数

另一种条件句形式

image-20220807102142758

函数print的返回值是None

Lecture 4 Higher-Order Functions

Higher-Order Functions 高阶函数

image-20220808095919018

currying 柯里化 把多参数函数化为单一参数高阶函数

Lecture 5 Environments

Decorator 装饰器

image-20220810112607368

Midterm

This expression/Evaluates to/Interactive Output

  • def delay(arg)
    	print('delayed')
        def g():
            return arg
        return g
    
    delay(delay)()(6)()
    """">>>
    	delayed
    	delayed
    	6
    """
    

Lecture 6 Recurion

Verifying Recurion Function

  1. Verify the base case
  2. Treat fact as a functional abstration
  3. Assume that fact(n-1) is correct
  4. Verify that fact(n) is correct, assuming that fact(n-1) is correct

Mutual Recurion 相互递归

def luhn_sum(n):
	if n < 10:
        return n
    else:
		all_but_last, last = split(n)
        return luhn_sum_double(all_but_last) + last

def luhn_sum_double(n):
	all_but_last, last = split(n)
    luhn_digit = sum_digits(2 * last)
    if n < 10:
		return luhn_digit
    else:
        return luhn_sum(all_but_last) + luhn_digit

Lecture 7 Tree Recursion

Tree-shaped processes arise whenever executing the body of a recursive function makes more than one call to that function.

Lecture 8 Sequences & Data Abstraction

  • Lists 列表
image-20220811155619280
  • for statement - sequence unpacking
image-20220811164407829
  • range 注意序列值域,左包括,右不包括
image-20220813111931270
  • List comprehension 列表推导式

语法规范:

 out_list = [out_express for out_express in input_list if out_express_condition] 

其中的 if 条件判断根据需要可有可无。

image-20220813113038765
  • Abstraction barrier 以有理数的抽象为例
image-20220813170621055

违反抽象界限的例子:

image-20220813170836217
  • Data Abstraction 只关心通过数据“行为”进行的表示,而不关心具体实现——即通过数据使用的行为可定义数据的表示。

例:使用函数而非列表构造的有理数Data Implementation

image-20220813182732822
  • Dictionary 字典 a congregation of key-value pairs 键值对的集合

  • Lists的复杂操作:

Lecture 9 Functional Decomposition & Debugging

关于python编程应对错误的几个特性

reduce try

Lecture 10 Tree

  • Slicing

切片,会创建新的list

image-20220818225817223