파이썬 목록에서 요소 제거
myList.remove(item) # Removes first instance of "item" from myList
myList.pop(i) # Removes and returns item at myList[i]
목록에서 요소 제거
>>> a = [0, 2, 3, 2]
>>> a.remove(2)
>>> a
[0, 3, 2]
파이썬 목록에서 요소를 제거하는 방법
# Basic syntax:
my_list.remove(element)
# Note, .remove(element) removes the first matching element it finds in
# the list.
# Example usage:
animals = ['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']
animals.remove('rabbit')
print(animals)
--> ['cat', 'dog', 'guinea pig', 'rabbit'] # Note only 1st instance of
# rabbit was removed from the list.
# Note, if you want to remove all instances of an element, convert the
# list to a set and back to a list, and then run .remove(element) E.g.:
animals = list(set['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']))
animals.remove('rabbit')
print(animals)
--> ['cat', 'dog', 'guinea pig']
목록 파이썬을 삭제하는 방법
# delete by index
a = ['a', 'b', 'c', 'd']
a.pop(0)
print(a)
['b', 'c', 'd']
목록 파이썬에서 항목을 삭제하는 방법
myList = ['Item', 'Item', 'Delete Me!', 'Item']
del myList[2] # myList now equals ['Item', 'Item', 'Item']
목록 파이썬의 모든 요소 삭제
mylist = [1, 2, 3, 4]
mylist.clear()
print(mylist)
# []