문서 편집 권한이 없습니다. 다음 이유를 확인해주세요:
요청한 명령은 다음 권한을 가진 사용자에게 제한됩니다: 사용자.
== 문자열 == #문자열 치환 ##문자열 치환시는 replace 함수 사용 ##:* 콤마(,) 를 파이프(|)로 치환하는 예제 ##:<source lang=python> text = 'aaa,bbb,ccc,ddd' result = text.replace(",","|") </source> ##2번째 , 까지만 치환할 경우, 파라미터에 2 추가 ##:<source lang=python> text = 'aaa,bbb,ccc,ddd' result = text.replace(",","|", 2) </source> == 리스트 == {{틀:요점 |내용=<big>[</big> , , <big>]</big>로 선언됨 * 리스트 = [값, 값, 값] }} <source lang=python> person = ['james', 17, 175.3, True] </source> # range를 사용하여 리스트 만들기 * 리스트 = list(range(횟수)) <source lang=python> a = list(range(10)) </source> # apend() 로 추가 하기 <source lang=python> a.append([500,600]) </source> # extend() 로 확장 하기 <source lang=python> a.extend([500,600]) </source> # insert() 로 값 중간에 끼워넣기 <source lang=python> a.insert(2, 500) </source> # pop() 으로 마지막 항목 삭제 <source lang=python> a.pop() a.pop(1) 1번인덱스 항목 삭제 </source> # del 로 삭제 <source lang=python> del a[1] </source> # remove()로 값을 찾아서 삭제 <source lang=python> a.remove(20) </source> # reverse()로 순서 뒤집기 <source lang=python> a.reverse() </source> # sort()로 정렬하기 <source lang=python> a.sort(생략,reverse=False) : 오름차순 a.sort(reverse=True) : 내림차순 </source> # sorted()로 정렬된 신규 리스트 생성 <source lang=python> a.sorted(b) </source> # clear()로 리스트 모든항목 삭제 <source lang=python> a.clear() del a[:]로도 가능 </source> === 리스트 in 딕셔너리 === === 리스트내 딕셔너리 정렬 === <source lang=python> people = [ {'name': 'kim', 'age': 10}, {'name': 'lee', 'age': 20}, {'name': 'park', 'age': 30}, {'name': 'choi', 'age': 40}, {'name': 'kim', 'age': 50}, ] </source> ==== [방법1] sorted()+ lambda ==== - sorted()와 lambda를 사용하여 name으로 오름차순 정렬 후 age로 오름차순 정렬 <source lang=python> data = sorted(people, key=lambda person: (person['name'], person['age'])) for d in data: print(d) # {'name': 'choi', 'age': 40} # {'name': 'kim', 'age': 10} # {'name': 'kim', 'age': 50} # {'name': 'lee', 'age': 20} # {'name': 'park', 'age': 30} </source> ==== [방법2] sorted() + itemgetter (추천) ==== - sorted()와 itemgetter를 사용하여 name으로 오름차순 정렬 후 age로 오름차순 정렬 <source lang=python> from operator import itemgetter data = sorted(people, key=itemgetter('name', 'age')) for d in data: print(d) # {'name': 'choi', 'age': 40} # {'name': 'kim', 'age': 10} # {'name': 'kim', 'age': 50} # {'name': 'lee', 'age': 20} # {'name': 'park', 'age': 30} </source> == 튜플 == {{틀:요점 |내용=<big>( , , , )</big> 로 선언 * 리스트처럼 요소를 일렬로 저장하지만, 안에 저장된 요소를 변경, 추가, 삭제를 할 수 없습니다. '''읽기전용 리스트''' * 튜플 = (값, 값, 값) * 튜플 = 값, 값, 값 }} <source lang=python> a = (38, 21, 53, 62, 19) </source> == 딕셔너리 == * 딕셔너리 = {'키':'값','키':값} {{틀:요점 |내용=<big> { }</big> 로 선언 * 딕셔너리 = {'키':'값','키':값} }} <source lang=python> person = {'name': 'smith', 'age': 23} person = dict( name='smith', age=23 ) </source> [[Category:python]]
문서 저장 미리 보기 차이 보기 취소