MicrolearnENPTES

Comprehensions

Lesson 16 of 20 · Py.Micro

Build a new list from another in one readable line.

with_tax = [round(p * 1.2, 2) for p in prices]

The loop and the append in one line: for each price, compute the price with tax. The result is a new list.

Do it in the browser: a real Python tool, a short mission and instant feedback. No install.

Start this lesson — free
← DictionariesFunctions →

All lessons · Py.Micro