Log in from a computer to take this course

You'll need to log in from a computer to start Learn Python 2. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

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."
  1. In the above example, we create a list with 4 numbers in it.
  2. Then we loop through the numbers list and store each item in the list in the variable number.
  3. On each loop, if number is greater than 6, we print it out. So, we print 7.
  4. 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 a.

Like step 3 above, if the number is even, print it out. You can test if the item % 2 == 0 to help you out.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?