本系列为加州伯克利大学著名 Python 基础课程 CS61A 的课堂笔记整理,全英文内容,文末附词汇解释。
目录
02 Names, Assignment, and User-Defined Functions
02-2 Calling User-Defined Functions 调用函数
02-3 Looking Up Names In Environments 查找名称
04 Miscellaneous Python Features
01 Types of Expressions
An expression describes a computation and evaluates to a value - F(x)
max(1, 500)
min(-2, 200)
from operator import add, mul
add(2, 3)
mul(4, 5)
mul(add(2, mul(4,6)), add(3,5))
Anatomy of a Call expression:


02 Names, Assignment, and User-Defined Functions
ctrl + L //清空屏幕
from math import pi, sin
pi //3.1415926
sin //<built-in function sin>
sin(pi / 2)
radius = 10
area, circ = pi * radius * radius, 2 * pi * radius //area不随radius的改变而改变
max(1, 2, 3)
f = max
f //<built-in funciton max>
max //<built-in function max>
f(1, 2, 3)
max = 7
max //7
max = f //换回来吧宝贝
f //<built-in funciton max>
max //<built-in function max>
max(1, 2, 3)
from operator import add, mul
add //<built-in function add>
mul //<built-in function mul>
def square(x):
return mul(x,x)
square //<function square at 十六进制地址>
//书接上回
def areas():
return pi * radius * radius //area随radius的改变而改变
02-1 Defining Functions 定义函数
A more powerful means of abstraction: binds names to expressions / a series of statement

最低0.47元/天 解锁文章
1344

被折叠的 条评论
为什么被折叠?



