The recipe
Line 1 makes a list named nums: four numbers inside square brackets, kept in order. Each item sits at a position, its index, counting from 0. Our job: build a new list from it.
Lines 2 to 5 are one list comprehension: a recipe for a new list, written inside square brackets. It has an expression, n * 10, a for clause that walks through nums, and an optional if clause that filters.
One item at a time
Python runs the for clause first. It takes the items of nums one at a time, from left to right, and gives each one the name n. Right now n is 4.
Next the if clause tests n. Is 4 > 2? Yes, so the test is True and 4 gets through the filter, on to the expression.
Only now does the expression on line 3 run: n * 10 gives 40. The comprehension adds 40 to the end of the new list, which grows from [] to [40].
Back to the for: n is now 1. Is 1 > 2? No, the test is False, so the if drops 1. The expression never runs for it and nothing is added.
n becomes 5. 5 > 2 is True, so the expression runs: 5 * 10 is 50. It goes on the end, after 40, so the new list keeps the order of nums.
Last item: n is 2. Is 2 > 2? No: 2 is not bigger than itself, so the test is False and 2 is dropped. nums has no items left, so the for stops.
The result
The comprehension hands back the finished list, and = on line 2 gives it the name big. nums is not changed. The name n lived only inside the comprehension, so now it is gone.
The comprehension does what this loop does: start with [], and for each item that passes the test, append the expression. Same result, written as one expression. Unlike the comprehension, the loop leaves n behind.
Try it yourself
;; step 1/10 · line 1 >>> nums = [4, 1, 5, 2] >>> nums[0] # indexes count from 0 4 >>> len(nums) 4
The comprehension is split over four lines so each part gets its own line; Python joins lines inside brackets, so it is the same as big = [n * 10 for n in nums if n > 2]. For each item Python runs the clauses in the order for, then if, then the expression, even though the expression is written first.