append()
Adds an element at the end of the list
company = ['apple', 'microsoft', 'adobe'] company.append('oneplus') print(company)
clear()
Removes all the elements from the list
fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.clear() print(fruits)
copy()
Returns a copy of the list
fruits = ['apple', 'banana', 'cherry', 'orange'] x = fruits.copy() print(x)
count()
Returns the number of elements with the specified value
fruits = ['apple', 'banana', 'cherry', 'orange'] x = fruits.count("cherry") print(x)
extend()
Add the elements of a list (or any iterable), to the end of the current list
fruits = ['apple', 'banana', 'cherry', 'orange'] cars = ['Ford', 'BMW', 'Volvo'] fruits.extend(cars) print(fruits)
index()
Returns the index of the first element with the specified value
fruits = ['apple', 'banana', 'cherry', 'orange'] x = fruits.index("cherry") print(x)
insert()
Adds an element at the specified position
fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.insert(1, "mango") print(fruits)
pop()
Removes the element at the specified position
fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.pop(1) print(fruits)
remove()
Removes the first item with the specified value
fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.remove("banana") print(fruits)
reverse()
- Reverses the order of the list
fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.reverse() print(fruits)
sort()
- Sorts the list
fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.sort() print(fruits)
- Sorts the list
ย