Skip to content
Justice Tech School

Lists

A list holds many values in order. Indexes start at 0 and negative indexes count from the end. Use append to add and len to count.

A list comprehension builds a new list in one line.

Example
nums = [1, 2, 3]
nums.append(4)
print(nums[0], nums[-1])
print(len(nums))
print([n * 2 for n in nums])

Result

1 4
4
[2, 4, 6, 8]

Exercise

Add an item to the end.

fruits = ["apple"]
fruits.("mango")

Quiz Test

What is nums[-1]?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.