RivoCode

Python Basics · Data Structures · Lesson 15 of 36

Lists

Concept

Lists

Lists are ordered, changeable collections, created with square brackets.

Lists can hold mixed types and can be sliced with fruits[1:3] to grab a range of items, similar to slicing a string.

By the end of this lesson
  • Explain the core idea behind Lists.
  • Predict output before running a change.
  • Test one realistic and one unusual input.
  • Use the result to make the next decision.
How to study this page
  1. 1. Read one concept.
  2. 2. Change the example.
  3. 3. Run, compare, and explain.
  4. 4. Complete the challenge below.
Syntax
my_list = [item1, item2, item3]
my_list.append(item)
ExampleRunnable
fruits = ["apple", "banana", "mango"]
fruits.append("kiwi")
print(fruits[0], len(fruits))
Try it Yourself »
Slicing a list
fruits = ["apple", "banana", "mango", "kiwi"]
print(fruits[1:3])
Note: Slicing [start:stop] includes start but excludes stop, same rule as range().
Self-check before continuing

Without looking at the example, describe what changes when you modify one input in Lists. Then reopen the editor and prove your explanation with a small test.

You are ready to continue when you can predict, test, and explain the result.

Your turn

Create a list of 5 courses and print the third one.

Loading editor…

Console

Output will appear here...