5.2. The del statement
del선언
There is a way to remove an item from a list given its index instead of its value: the del statement. This differs from the pop() method which returns a value. The del statement can also be used to remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice). For example:
리스트에서 어떤 항목을 지우려면 그 항목의 값 대신 그 항목의 인덱스를 이용할 수 있습니다. 이것을 del 선언이라 합니다. pop()메소드와 달리, del선언은 리스트에서 슬라이스(여러 항목)를 지우거나 전체 리스트를 없애버릴 수 있습니다. (우리는 앞에서 슬라이스를 빈 것으로 설정하여 리스트 내용을 지워버린 적이 있습니다.)
>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a[0] # del과 인덱스를 통한 리스트 항목 지우기
>>> a
[1, 66.25, 333, 333, 1234.5]
>>> del a[2:4] # del 과 슬라이스를 이용한 리스트 항목 지우기
>>> a
[1, 66.25, 1234.5]
>>> del a[:] # del과 구간지정을 이용한 리스트 전체 지우기
>>> a
[]
del can also be used to delete entire variables:del은 변수 자체를 지워버릴 수도 있습니다.
>>> del a
Referencing the name a hereafter is an error (at least until another value is assigned to it). We’ll find other uses for del later.del a를 실행 한 뒤 a를 부르면 오류가 발생합니다. a에 다시 값이 설정되기 전까지 말입니다. 우리는 나중에 del이 또 어떤 곳에 사용될 수 있는지 살펴볼 것입니다.