Codzy

Lists

A list stores several values in order, between square brackets: [1, 2, 3]. You access an item with its index, which starts at 0: fruits[0] is the first one.

A list can change: .append() adds an item at the end, len() gives the number of items and sum() adds numbers together. You can also go through a list with a for loop.

fruits = ["apple", "banana", "cherry"]
print(fruits[0])
print(len(fruits))
fruits.append("kiwi")
print(fruits)
for f in fruits:
    print(f)

Start the lesson