티스토리 뷰
728x90
반응형
member_group = ['Rachel', 'Monica', 'Phoebe', 'Ola', 'You']
# 항목추가
member_group.append('ducati')
print(member_group)
# 항목 삽입
member_group.insert(0, 'honda')
print(member_group)
# del 문으로 제거
del member_group[1]
print(member_group)
# 축출
ele_ducati = member_group.pop()
print(ele_ducati)
# 축출 후 바로 제거
del_ele_you = member_group.pop(len(member_group)-1)
print(del_ele_you)
# 항목을 리스트에서 제거하고 다시 쓸 일이 없다면 del문 / 항목을 리스트에서 제거하고 어딘가에 사용할 거라면 pop()메서드
# 값으로 항목 제거
motorcycles = ['honda', 'yamaha', 'suzuki', 'ducati']
motorcycles.remove('ducati')
print(motorcycles)
# 만약 리스트에 같은 값이 여러개 있다면 remove() 메서드는 첫번째 항목만 제거 / 값을 전부 제거하려면 루프를 써야함.
# sort() 로 리스트 정렬
cars = ['bmw', 'audi', 'toyota', 'subaru']
# 알파벳순 정렬
cars.sort()
print(cars)
# 알파벳 반대순 정렬
cars.sort(reverse=True)
print(cars)
# 리스트 임시정렬 - 리스트의 원래의 순서를 유지하면서 정렬된 순서로 표현 혹은 출력만 하려 할때
print(sorted(cars))
# 알파벳 반대순 임시정렬
print(sorted(cars, reverse=True))
print(cars)
# 알파벳 순과 상관없이 무조건 반대순서로 출력
cars.reverse()
print(cars)
# 리스트 길이 구하기
print('cars len =', len(cars))
# 리스트 루프
peoples = ['alice', 'david', 'carolina']
# 왠만하면 명명규칙대로 사용하는 편이 좋다. - for 단수 in 복수 :
for people in peoples:
print(people.title()+', that was a great trick!')
print("I can't wait to see your next trick, "+people.title()+".\n")
728x90
반응형
'Programming language > Python' 카테고리의 다른 글
파이썬 문법5 - 딕셔너리 (0) | 2018.07.10 |
---|---|
파이썬 문법4 - if 문 (0) | 2018.07.09 |
파이썬 문법3-2 / 리스트 (0) | 2018.07.06 |
파이썬 문법2 / 문자열 (0) | 2018.07.05 |
파이썬 문법1 - 변수 (0) | 2016.07.28 |
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- cordova
- Vue3
- git checkout -b
- svg모션
- icon font
- 리프래시토큰
- React.StrictMode
- svg 폰트
- 아이콘 폰트 만들기
- 내장요소
- for of 구문
- 코도바
- 앵귤러
- IntrinsicElements
- Intrinsic
- 반복문
- Angular
- CSS
- RefreshToken
- interceptors
- JsDoc
- git
- Aptana
- react
- svg icon font
- vue-router
- react-router-dom
- 자바스크립트
- 태그
- anime.js
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함