list comprehension if else 1

list comprehension if else

[statement if condition else statement for _ in iterable_object]
#statement are without assignment

Here is what the above code is Doing:
1. We create a list of numbers from 0 to 9.
2. We create a list of strings from the list of numbers. The list contains the string “Even” if the number is even, otherwise the string is “Odd”.
3. We print the modified list.

Similar Posts