Learn

In programming, it is common to want to work with collections of data. In Python, a list is one of the many built-in data structures that allows us to work with a collection of data in sequential order.

Suppose we want to make a list of the heights of students in a class:

  • Noelle is 61 inches tall
  • Ava is 70 inches tall
  • Sam is 67 inches tall
  • Mia is 64 inches tall

In Python, we can create a variable called heights to store these integers into a list:

heights = [61, 70, 67, 64]

Notice that:

  1. A list begins and ends with square brackets ([ and ]).
  2. Each item (i.e., 67 or 70) is separated by a comma (,)
  3. It’s considered good practice to insert a space () after each comma, but your code will run just fine if you forget the space.

Let’s write our own list!

Instructions

1.

Examine the existing list heights in your code editor.

A new student just joined the class!

  • Chloe is 65 inches tall

Add Chloe’s height to the end of the list heights.

2.

Remove the # in front of the definition of the list broken_heights. If you run this code, you’ll get an error in your terminal:

SyntaxError: invalid syntax

Add commas (,) to broken_heights so that it runs without errors.

Sign up to start coding

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?