List Comprehension

簡潔的列表生成方式。

squares = [x**2 for x in range(10)]
evens = [x for x in range(10) if x % 2 == 0]
💻 程式碼編輯器
📤 執行結果
等待執行...
← 上一課 下一課 →