파이썬 unshift, shift, push, pop

116.32.133.50 (토론)님의 2023년 3월 22일 (수) 02:05 판 (→‎unshift: insert())
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

파이썬 unshift, shift, push, pop
  • insert(), pop(), append() 메소드로 구현

Unshift-shit-push-pop.jpg

2 unshift: insert(0)[ | ]

fruits = ["Apple", "Banana", "Orange"]
fruits.insert(0, "Lemon")
print(fruits) # ['Lemon', 'Apple', 'Banana', 'Orange']

3 shift: pop(0)[ | ]

fruits = ["Apple", "Banana", "Orange"]
element = fruits.pop(0)
print(element) # Apple
print (fruits) # ['Banana', 'Orange']

4 push: append()[ | ]

fruits = ["Apple", "Banana", "Orange"]
fruits.append("Lemon")
print (fruits) # ['Apple', 'Banana', 'Orange', 'Lemon']

5 pop: pop()[ | ]

fruits = ["Apple", "Banana", "Orange"]
element = fruits.pop()
print (element) # Orange
print (fruits) # ['Apple', 'Banana']

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}