本 Wiki 开启了 HTTPS。但由于同 IP 的 Blog 也开启了 HTTPS,因此本站必须要支持 SNI 的浏览器才能浏览。为了兼容一部分浏览器,本站保留了 HTTP 作为兼容。如果您的浏览器支持 SNI,请尽量通过 HTTPS 访问本站,谢谢!
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版后一修订版两侧同时换到之后的修订记录 | ||
cs:fundamental:cs61a:week_1 [2023/09/26 03:50] – codinghare | cs:fundamental:cs61a:week_1 [2023/09/26 04:20] – [Control] codinghare | ||
---|---|---|---|
行 219: | 行 219: | ||
==python 的运算符== | ==python 的运算符== | ||
* ''/ | * ''/ | ||
- | ====Designing Functions==== | + | ===Designing Functions=== |
+ | 函数设计应该遵循一个 idea: | ||
+ | >// | ||
+ | 具体的来说: | ||
+ | * 每个函数应该只对应一项工作,该工作可以很简单的描述。多个工作应该使用多个函数实现 | ||
+ | * DRY(//do not repeat yourself// | ||
+ | * 函数应该被定义为更泛化的形式。比如比起 '' | ||
+ | ==Documentation== | ||
+ | python 中通常包括了函数的描述,这类 documentation 被称为 // | ||
+ | * // | ||
+ | * // | ||
+ | <code py> | ||
+ | >>> | ||
+ | """ | ||
+ | |||
+ | Applies the ideal gas law: http:// | ||
+ | |||
+ | v -- volume of gas, in cubic meters | ||
+ | t -- absolute temperature in degrees kelvin | ||
+ | n -- particles of gas | ||
+ | """ | ||
+ | k = 1.38e-23 | ||
+ | return n * k * t / v | ||
+ | </ | ||
+ | 还有一类以 ''#'' | ||
+ | [[https:// | ||
+ | ====Control statement==== | ||
+ | ===statement=== | ||
+ | // | ||
+ | * 我们评估(// | ||
+ | * 我们执行(// | ||
+ | // | ||
+ | <code py> | ||
+ | >>> | ||
+ | mul(x, x) # Watch out! This call doesn' | ||
+ | </ | ||
+ | 如果希望应用修改(返回返回值),则需要使用 '' | ||
+ | <code py> | ||
+ | >>> | ||
+ | return mul(x, x) | ||
+ | </ | ||
+ | ==Compound Statements== |