Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Tutorial 4: Data Structures

Similar presentations


Presentation on theme: "Python Tutorial 4: Data Structures"— Presentation transcript:

1 Python Tutorial 4: Data Structures

2 List 값을 순차적으로 저장하기 위한 자료 구조 여러 자료형이 저장 가능 중복값 저장 가능 Order Index
값을 저장하는 위치(Slot) Element Slot에 들어가는 값 여러 자료형이 저장 가능 중복값 저장 가능

3 Methods 생성 입력 .append() 기존 list의 마지막에 추가로 붙여넣는다

4 Methods 제거 0번 index부터 순차적으로 검색해서 처음 발견한 element를 삭제

5 Index Index 1 2 3 4 5 8 12 15 Element Index -6 -5 -4 -3 -2 -1 1 2 4 8
1 2 3 4 5 8 12 15 Element Index -6 -5 -4 -3 -2 -1 1 2 4 8 12 15 Element

6 Index .insert() .extend() 특정 index에 값을 넣는다 리스트를 한꺼번에 append()
colors + [‘purple’, ‘black’] 과 동일

7 Slicing Index 1 2 3 4 5 6 7 8 12 15 17 Element 2 3 4 8 1 2 4 3 6 1 8 17 1 3 5 2 8 15

8 Set 집합 .append(), .insert(), .extend()가 없다 { } 순서(Order)가 중요하지 않다
중복 데이터 불가 .append(), .insert(), .extend()가 없다 순서가 의미가 없기 때문에 .add()로 element를 추가

9 Method .union() .intersection()

10 Tuple 리스트와 유사 차이점 읽기 전용(Read Only) Method가 몇 개 없다 메모리를 적게 사용한다 속도가 빠르다

11 Packing, Unpacking Packing Unpacking

12 Dictionary Key : Value 의 구조 인덱스(index)를 사용하지 않는다 Key가 index의 역할을 대신
순서가 중요하지 않다 없는 키를 접근하려고 하면 에러 발생

13 Dictionary 사용법 member 딕셔너리를 생성하고 값을 할당 [key]:[value]의 쌍을 이루고 있다

14 Adding and Deleting Elements
딕셔너리에 새로운 key-value 쌍을 추가 ‘del’ statement로 원하는 key-value 쌍을 삭제할 수 있다 member.clear() -> remove all entries in the dictionary del member -> delete entire dictionary

15 Iteration 호출할 때 Key가 존재하지 않으면 error .items() .keys() .values()
in 연산자를 이용해서 에러를 피할 수 있다 [key] in [dictionary] True if the key exists False if not .items() ([key], [value])의 dict objec를 retur한다 .keys() .values()


Download ppt "Python Tutorial 4: Data Structures"

Similar presentations


Ads by Google