evens_to_50 = [i for i in range(51) if i % 2 == 0] print evens_to_50
This code generates a list of even numbers up to fifty. But for me, as a new thing in programming, some moments are incomprehensible -:
- Why generation occurs in square brackets, they are usually used when working with indexes
- What does the first i do before the for loop? Why, after range (51), there is no colon and a new line with tabulation?
- Where else can brackets be used?
- In square brackets you can write as many if or for ? What are the rules in them?