Table of Contents
-
p12
>>> zipcode = 02492 SytanError: invalid token >>> zipcode = 02132 >>> zipcode 1114 Why: 8进制
-
p15
数学运算符的操作顺序: PEMDAS(parentheses, exponentiation, multiplication,
division, addition, substraction, 乘法和除法优先级相同,加法和减法优先级相同)
- p40
封装(encapsulation): 将一组语句转换成函数定义的过程
泛化(generalization): 将一些不必要的具体值(如一个数字)替换为合适的通用参数或变量
的过程。
关键词参数(keyword argument): 调用函数时,附带了参数名称的参数。
接口(interface): 描述函数如何使用的说明。包括函数的名称,以及形参与返回值的说明。
重构(refactoring): 修改代码并改善函数的接口以及代码质量的过程。
- p41
练习 4-2, 4-3
-
p63
def factorial(n): space = ' ' * (4 * n) print space, 'factorial', n if n == 0: print space, 'returning 1' return 1 else: result = n * factorial(n-1) print space, 'returning', result return result
-
p96
如果切片操作符出现在赋值语句的左侧,则可以更新多个元素
>>> t = [1, 2, 3, 4, 5] >>> t[1:3] = [7, 8] >>> print t [1, 7, 8, 2, 3, 4, 5]
- p97
列表的方法全都是没有返回值的,它们修改列表,并返回 None
- p98
列表删除元素:
- L.pop([index]) -> item -- remove and return item at index (default last). - L.remove(value) -- remove first occurrence of value. - del L[index[:index]] 删除元素,可使用切片删除多个.