CS61A学习记录
六月 21, 2024
1700
Homework
hw01
CS61/CS61A/hw/hw01 at main · zlh123123/CS61 (github.com)
hw01还是一些基础的python语法练习,下面介绍了一个语法现象。
1 |
|
这里涉及到python中的纯函数与非纯函数。对于纯函数而言,其接收输入产生输出,不会产生其他影响;例如abs()
函数,只会返回输入值的绝对值。对于非纯函数而言,其除了输入和输出外,还会对系统产生其他影响;例如print()
函数,其功能是打印输入值,而其返回值是None
。
在with_if_function()
函数中,首先依次运行的是cond()
,true_func()
,false_func()
三个函数。cond()
函数返回False
;true_func()
函数返回None
,并打印42;false_func()
函数同理。因此,运行result = with_if_function()
后,会同时打印42和47两个值。最后运行print(result)
后,打印false_func()
对应的返回值None
。
hw02
Lab
Exam
Project
- 本文作者:Linghao Zhang
- 本文链接:http://zlh123123.github.io/2024/06/21/CS61A%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95/index.html
- 版权声明:本博客所有文章均采用 BY-NC-SA 许可协议,转载请注明出处!