## Summary ## 本章小结 * A loop is used to repeat code as many times as needed. * We use a `for` loop when we know how many iterations the loop will do; we use a while loop when we don’t know how many iterations a loop will do. * Python uses indentation to determine which lines of code go together. * A dictionary is a mapping from keys (such as words) to values (such as their frequencies). * We need to open a file before we can read from it. * Once a file is open, we can use methods or a loop to read its lines. * Some modules (such as csv and zipfile) come with Python and can be used by importing them. * Other modules, such as matplotlib, need to be installed first before they can be imported and used. <!-- --> * 循环用于根据需要重复执行代码多次。 * 当我们明确知道循环将执行的迭代次数时,使用 `for` 循环;而在不确定循环将执行多少次迭代时,则采用 while 循环。 * Python 通过缩进来判断哪些代码行应该组合在一起。 * 字典是从键(例如单词)到值(例如它们的频率)的映射。 * 我们必须先打开一个文件,才能开始从中读取数据。 * 文件打开后,我们可以使用方法或循环来逐行读取。 * 一些模块(如 csv 和 zipfile)是 Python 自带的,可以直接通过导入来使用。 * 其他模块,例如 matplotlib,需先安装之后才能导入和使用。
Activity