A list is an ordered, changeable (mutable) collection of values. You write it with square brackets and commas: nums = [10, 20, 30]. A list may contain values of mixed types, duplicates and even other lists, so [1, "two", 3.0, [4]] is perfectly legal. An empty list is [] or list(). You can also build a list from any iterable, so list("abc") is ['a', 'b', 'c'] and list(range(3)) is [0, 1, 2]. Two operators build new lists from old ones: + concatenates ([1, 2] + [3] is [1, 2, 3]) and * repeats ([0] * 3 is [0, 0, 0]). Lists matter because almost every real program handles a collection of things: scores, names, readings or lines of a file.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.