Generate a for loop in Python


#define array (you can also drop this directly into the for loop)
a = [1,2,3,4,5]
#loop through array, a
for i in a:
    #for each element i in array a, add 3
    k = i + 3
    #print result
    print(k)
else:
    #once loop is finished, print complete
    print('Complete')
#output
4
5
6
7
8
Complete


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.