1. append() method adds an element to the end of the list:
numbers = [1, 2, 3]
numbers.append(4)
print(numbers) # Output: [1, 2, 3, 4]
2. extend() method adds multiple elements to the end of the list:
numbers = [1, 2, 3]
numbers.extend([4, 5])
print(numbers) # Output: [1, 2, 3, 4, 5]
3. insert() method inserts an element at a specific index:
fruits = ["apple", "banana", "orange"]
fruits.insert(1, "grape")
print(fruits) # Output: ["apple", "grape", "banana", "orange"]
4. remove() method removes the first occurrence of an element:
fruits = ["apple", "banana", "orange"]
fruits.remove("banana")
print(fruits) # Output: ["apple", "orange"]
5. pop() method removes and returns the last element of the list:
numbers = [1, 2, 3]
last_number = numbers.pop()
print(last_number) # Output: 3
print(numbers) # Output: [1, 2]
6. index() method returns the index of the first occurrence of an element:
fruits = ["apple", "banana", "orange"]
index_of_banana = fruits.index("banana")
print(index_of_banana) # Output: 1
7. count() method returns the number of occurrences of an element in the list:
numbers = [1, 2, 3, 2, 1]
number_of_ones = numbers.count(1)
print(number_of_ones) # Output: 2
8. sort() method sorts the list in ascending order:
numbers = [3, 1, 4, 2]
numbers.sort()
print(numbers) # Output: [1, 2, 3, 4]
9. reverse() method reverses the order of the list:
numbers = [1, 2, 3]
numbers.reverse()
print(numbers) # Output: [3, 2, 1]
#python
@oroscholarly Oroscholarly.gaammeemedia.com