본문 바로가기
Python 배우기

list_operations.py

by 노화방지 Anti-aging Hairstyle 2016. 3. 7.
반응형
animals = ['elephant', 'lion', 'tiger', "giraffe"]  # create new list
print(animals)

animals += ["monkey", 'dog'] # add two items to the list
print(animals)

animals.append("dino") # add one more item to the list using append() method
print(animals)

animals[6] = 'dinosaur'
print(animals)

산출물 (Output)


['elephant', 'lion', 'tiger', 'giraffe'] ['elephant', 'lion', 'tiger', 'giraffe', 'monkey', 'dog'] ['elephant', 'lion', 'tiger', 'giraffe', 'monkey', 'dog', 'dino'] ['elephant', 'lion', 'tiger', 'giraffe', 'monkey', 'dog', 'dinosaur']



* append() method와 concatenation을 사용하여 list의 끝에 새로운 item을 추가할 수 있습니다.
Unlike strings과 달리, lists는 mutable 타입인데, 즉, lst[index] = new_item를 사용하여 그 content를 변경할 수 있습니다.

Replace 'dino' with "dinosaur" in the "animals" list.


반응형

'Python 배우기' 카테고리의 다른 글

tuples.py  (0) 2016.03.07
list_items.py  (0) 2016.03.07
lists.py  (0) 2016.03.06
string_methods.py  (0) 2016.03.06
character_escaping.py  (0) 2016.03.06

댓글