In python, what is returned when evaluating [n for n in range(10) if n % 2]?
![](https://pythonpoint.net/wp-content/uploads/2020/11/How-to-declare-array-in-python_-4-1024x576.jpg)
Expression “[n for n in range(10) if n%2]” will return a list in one go.
This creates a list of odd numbers between 0 and 9. The for loop goes from 0 to 9 and the number which is not divisible by 2 is added to the list.
[n for n in range(10) if n%2]
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-657-1024x356.png)
This code is a compact version of the code given below.
list=[] for n in range(10): if n%2: list.append(n) list
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-658-1024x280.png)
Subscribe
Login
Please login to comment
0 Discussion