Keep the evens · 只留下偶数
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
This one builds on a lesson you haven't finished yet. Do that lesson first: · 此任务基于您尚未完成的课程。请先完成以下课程:
Python Basics · Python 基础 · Functions · 函数 →
English
Keep the evens
Filter a list: keep some items and leave the rest out.
Start with an empty list, loop over nums, and .append() each number that passes the test n % 2 == 0. Return the new list after the loop has finished.
中文
只留下偶数
筛选列表:保留一部分元素,去掉其余的。
先建一个空列表,遍历 nums,把通过 n % 2 == 0 判断的数用 .append() 加进去。循环结束后返回这个新列表。
Write evens(nums) that returns a new · 新的 list holding only the even numbers from nums, in the same order. · 编写 evens(nums),返回一个新列表,只包含 nums 中的偶数,顺序不变。
Click Run to see the output here. · 点击“运行”查看此处输出。