-
[Python tutorial] 21. List/Array methods코딩/Python 2022. 12. 21. 17:18728x90
list.append(elmnt)
Adds an element at the end of the list
fruits = ['apple', 'banana', 'cherry'] fruits.append("orange")
list.clear()
Removes all the elements from the list
fruits = ['apple', 'banana', 'cherry', 'orange'] fruits.clear()
list.copy()
Returns a copy of the list
fruits = ['apple', 'banana', 'cherry', 'orange'] x = fruits.copy()
list.count(value)
Returns the number of elements with the specified value
fruits = ['apple', 'banana', 'cherry'] x = fruits.count("cherry")
list.extend(iterable)
Add the elements of a list (or any iterable), to the end of the current list
fruits = ['apple', 'banana', 'cherry'] cars = ['Ford', 'BMW', 'Volvo'] fruits.extend(cars)
list.index(elmnt)
Returns the index of the first element with the specified value
fruits = ['apple', 'banana', 'cherry'] x = fruits.index("cherry")
list.insert(pos, elmnt)
Adds an element at the specified position
fruits = ['apple', 'banana', 'cherry'] fruits.insert(1, "orange")
list.pop(pos)
Removes the element at the specified position
fruits = ['apple', 'banana', 'cherry'] fruits.pop(1)
list.remove(elmnt)
Removes the first item with the specified value
fruits = ['apple', 'banana', 'cherry'] fruits.remove("banana")
list.reverse()
Reverses the order of the list
fruits = ['apple', 'banana', 'cherry'] fruits.reverse()
list.sort(reverse=True|False, key=myFunc)
Sorts the list
cars = ['Ford', 'BMW', 'Volvo'] cars.sort()
728x90'코딩 > Python' 카테고리의 다른 글
[Python tutorial] 23. Tuple Methods (0) 2022.12.21 [Python tutorial] 22. Dictionary methods (0) 2022.12.21 [Python tutorial] 20. String methods (1) 2022.12.21 [Python tutorial] 19. Built-in Function (0) 2022.12.21 [Python tutorial] 18. File handling (0) 2022.12.21