파이썬 unshift, shift, push, pop

10000LAB (토론 | 기여)님의 2020년 1월 18일 (토) 13:17 판 (→‎같이 보기)
파이썬 insert, pop, append

1 unshift: insert()

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

2 shift: pop(0)

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

3 push: append()

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

4 pop: pop()

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

5 같이 보기

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