The blocks of code in a
for loop can be as big or as small as they need to be.
While looping, you may want to perform different actions depending on the particular item in the list.
numbers = [1, 3, 4, 7] for number in numbers: if number > 6: print number print "We printed 7."
- In the above example, we create a list with 4 numbers in it.
- Then we loop through the
numberslist and store each item in the list in the variable
- On each loop, if
numberis greater than 6, we
- Finally, we print out a sentence.
Make sure to keep track of your indentation or you may get confused!
Like step 2 above, loop through each item in the list called
Like step 3 above,
if the number is even,
if the item
% 2 == 0 to help you out.