1/23
Vocabulary flashcards defining Python list operations, methods, functions, slicing techniques, and error handling based on the classroom material.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
List Indexing
Accessing an item at a specific position using square brackets, such as numbers[1] to retrieve the second item in a list.
append()
A list method that adds a single item or object to the end of a list, such as numbers.append(40).
extend()
A list method that adds each item from an iterable (such as another list) to the end of the list.
append() vs. extend()
append() adds one single item to the end (which can be a nested list like [3, 4]), whereas extend() iterates through a collection and adds each item individually.
Negative Indexing
Accessing items relative to the end of the list using negative integers, where numbers[-1] gets the last item and numbers[-2] gets the second-to-last item.
List Slicing [start:stop]
Extracting a subset of a list starting at index start up to, but not including, index stop (e.g., numbers[1:4]).
List Item Assignment
Modifying a list in place by assigning a new value to a specific index, such as numbers[1] = 50.
len()
A built-in function that returns the total number of items in a list.
max()
A built-in function that returns the largest element in a list.
min()
A built-in function that returns the smallest element in a list.
Omitted Slice Start [:stop]
Slicing syntax that defaults to starting from index 0 up to, but not including, the stop index (e.g., numbers[:2]).
Omitted Slice Stop [start:]
Slicing syntax that starts at the start index and includes all remaining items through the end of the list (e.g., numbers[1:]).
Step Slicing [::step]
Slicing syntax that extracts items at regular intervals based on a step value (e.g., numbers[::2] gets every second item).
remove()
A list method that deletes the first occurrence of a specified value from a list.
pop()
A list method that removes and returns an item from a list (defaults to removing the last item if no index is specified).
insert()
A list method that places a new item at a specific index, shifting existing items to the right (e.g., numbers.insert(1, 15)).
sort()
A list method that rearranges elements in place in ascending numerical or alphabetical order.
reverse()
A list method that reverses the elements of a list in place.
in operator
A membership operator that returns True if a value is present in the list and False otherwise.
IndexError: list index out of range
An error raised when attempting to access an index that exceeds the valid bounds of a list (e.g., accessing numbers[3] on a 3-element list).
AttributeError (lists)
An error raised when invoking a method that does not exist on lists, such as numbers.add(40) instead of numbers.append(40).
TypeError (list indexing)
An error raised when attempting to call a list using parentheses () instead of indexing with square brackets [].
Out-of-Bounds List Slicing
Slicing with a stop index beyond the list length (e.g., numbers[1:5]) which executes safely without throwing an error and returns available items.
ValueError (list remove)
An error raised when calling remove() on a value that does not exist in the list (e.g., numbers.remove(50)).