伯克利 CS61A 课堂笔记 02 —— Functions

本系列为加州伯克利大学著名 Python 基础课程 CS61A 的课堂笔记整理,全英文内容,文末附词汇解释。

目录

01 Types of Expressions

02 Names, Assignment, and User-Defined Functions

02-1 Defining Functions 定义函数

02-2 Calling User-Defined Functions 调用函数

02-3 Looking Up Names In Environments 查找名称

03 Environment Diagrams

04 Miscellaneous Python Features

05 Print and None

附:词汇解释


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值