ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Python] 리스트 삭제
    언어/python 2021. 3. 3. 01:10

    리스트 삭제 방법 3가지

    - remove()
    - del
    - pop

     

    소스코드

    a = [1, 2, 3, 1, 2, 3]
    
    a.remove(2) # 맨 첫번째 x값 삭제
    del a[1] # x번째 index 삭제
    a.pop() # 맨 마지막 index 삭제
    a.pop(1) # x번째 index 삭제 

     

    결과

    [1, 3, 1, 2, 3]
    [1, 3, 1, 2, 3]
    [1, 2, 3, 1, 2]
    [1, 3, 1, 2, 3]

     

    '언어 > python' 카테고리의 다른 글

    순열과 조합 - combinations, permutations  (0) 2021.01.09

    댓글

Designed by black7375.