Jul 18, 2024
list.append(x)people.append('Luigi') adds 'Luigi' to people.list.clear()people.clear() results in an empty list.list.copy()copy_people = people.copy().
copy_people won't affect people.list.count(x)people.count('Elon') returns the count of 'Elon' in people.list.extend(iterable)people.extend(['apple', 'banana']) adds 'apple' and 'banana' to people.list.index(x)people.index('Trump') returns the index of 'Trump'.list.insert(i, x)people.insert(1, 'Luigi') inserts 'Luigi' at index 1.list.pop([i])people.pop(0) removes and returns the first element.list.remove(x)people.remove('Elon') removes the first 'Elon' in people.list.reverse()people.reverse() reverses the elements in people.list.sort(key=None, reverse=False)people.sort() sorts people alphabetically.
key for custom sort order.reverse=True sorts in descending order.End of Lecture.