먼저 차이를 보자면
del : 인덱스로 삭제
remove() : 값으로 삭제 라고 볼 수 있다.
예시를 통해 간단히 이해할 수 있다.
>>> int_list = [1, 2, 3, 4, 5, 6, 7]
>>> str_list = ['가','나','다','라','마']
>>> del int_list[0] # 한개의 요소를 삭제
>>> print(int_list)
[2, 3, 4, 5, 6, 7]
>>> del str_list[3:] # 여러개의 요소를 삭제
>>> print(str_list)
['가', '나', '다']
>>> numbers = [1, 2, 2, 3, 3, 3] # 숫자 3이 3개인 리스트
>>> numbers.remove(3)
>>> print(numbers)
[1, 2, 2, 3, 3] # 숫자 3이 2개로 줄어들었음
###############
>>> numbers = [1, 2, 2, 3, 3, 3]
>>> for _ in numbers :
>>> numbers.remove(3)
>>> print(numbers)
[1, 2, 2] # 숫자 3이 없음
'개발 > Python' 카테고리의 다른 글
[Python] sort, sorted 사용법 (0) | 2021.12.14 |
---|---|
[Python] isalpha(), isalnum(), maketrans() 함수 (0) | 2021.12.13 |
[Python] 절대값(abs) 함수 (0) | 2021.12.13 |
[Python] divmod 함수 (0) | 2021.12.10 |
[Python]AttributeError: module 'tweepy' has no attribute 'StreamListener' (0) | 2021.12.09 |
댓글