Keep the evens · เก็บเฉพาะเลขคู่
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, และ .append() แต่ละตัวเลขที่ผ่านการทดสอบ n % 2 == 0. คืนรายการใหม่หลังจากลูปเสร็จสิ้น
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. · คลิก Run เพื่อดูผลลัพธ์ที่นี่