Explanation:
1. List data
You have a list with three integers: 1, 2, and 3.
2. List Comprehension
This is a list comprehension with a condition. It means:
-
Loop over each item i in the list data
-
Condition: if i % 2 == 1 → Only include odd numbers
-
Action: i**2 → Square the value of i
Step-by-step Evaluation:
| i | i % 2 == 1 | Included? | i**2 |
|---|---|---|---|
| 1 | 1 % 2 == 1 → True | ✅ Yes | 1 |
| 2 | 2 % 2 == 1 → False | ❌ No | — |
| 3 | 3 % 2 == 1 → True | ✅ Yes | 9 |
Result
✅ Final Output:


0 Comments:
Post a Comment