This content originally appeared on DEV Community and was authored by HHMathewChan
Today, I just continue to do exercise on PYnative
Question
The question is to generate a list of all even number between 4 to 30.
The expected output is:
[4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]
Solution
At first, my solution is using a for loop to produce the list as follow:
list1 = []
for number in range(4,30):
if not number % 2:
list1.append(number)
print(list1)
But the recommended is really simple, just use the list(), which is:
print(list(range(4, 30, 2)))
My reflection
Now I learn a new function, should handle the same problem easily next time.
This content originally appeared on DEV Community and was authored by HHMathewChan

HHMathewChan | Sciencx (2022-06-01T21:49:38+00:00) Python daily exercise 1. Retrieved from https://www.scien.cx/2022/06/01/python-daily-exercise-1/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.