Module 10 of 15 · Step 1 of 15

Lists

A list keeps several values in a chosen order. Instead of making one variable for each language or score, put related values inside square brackets.

By the end of this lesson, you can:
  • Create and read list items
  • Explain zero-based and negative indexes
  • Change, append, and remove items
  • Count and loop through a list
Lists lesson progress0%

Course progress: 0% · 0 of 15 steps completed in this module

Learn · Keep related values together
Concept 1 of 6

Keep related values together

Write items between square brackets, separated by commas. A list can mix types, though keeping similar kinds together is often clearer for beginners. The order of items is remembered.

Pattern
languages = ["Python", "C", "Java"]
Code
languages = ["Python", "C", "Java"]
print(languages)
Output
['Python', 'C', 'Java']

Why it works

  1. Square brackets create one list.
  2. Commas separate its three text items.
  3. Printing a whole list shows its bracketed representation.

Common mistake

Not this
languages = "Python", "C", "Java"
Try this
languages = ["Python", "C", "Java"]

Square brackets make the intended list explicit.