Lists and List Methods
A list holds many values in order, in a single variable. Lists are the most used data structure in Python: to-do items, scores, names, rows of data. In this lesson you will create lists, read from them, and change them with built-in methods.
What You'll Learn
- Creating lists and accessing items by index
- Slicing to grab parts of a list
- Adding and removing items
- Sorting and useful built-in functions
Creating and Accessing
Loading Python Playground...
Like strings, lists index from 0, and -1 is the last item.
Loading Python Exercise...
Slicing
Loading Python Playground...
Changing a List
Unlike strings, lists are mutable: you can change them in place.
Loading Python Playground...
Loading Python Exercise...
Loading Python Exercise...
Sorting
sort() reorders the list in place; add reverse=True for descending:
Loading Python Playground...
Loading Python Exercise...
Built-in Helpers
Loading Python Playground...
Key Takeaways
- Lists use square brackets:
[1, 2, 3] - Index from
0,-1from the end; slice with[start:end] - Lists are mutable:
append(),insert(),remove(),pop() sort()reorders in place,reverse=Truefor descendinglen(),max(),min(),sum()summarize a list
Quiz
Question 1 of 425% Complete
0 of 4 questions answered

