loop append to list python 1

loop append to list python

a=[]
for i in range(5):    
    a.append(i)
print(a)
# [0, 1, 2, 3, 4]

Here is what the above code is Doing:
1. We create an empty list a.
2. We loop over the range(5) object.
3. We append the current value of i to the list a.
4. We print the list a.

Similar Posts