SlideShare a Scribd company logo
1 of 30
PYTHON
ARRAY
모듈
Moon Yong Joon
Array 기초
Array 생성 규칙
array 클래스를 이용해 동일한 타입값(typecode)으
로 인스턴스를 생성하기
array.array(typecode[, initializer])
Array 변수 : type codes
array.array 지정 시 타입코드
type code C Type Python Type Minimum size in bytes
'b' signed char int 1
'B' unsigned char int 1
'u' Py_UNICODE Unicode character 2
'h' signed short int 2
'H' unsigned short int 2
'i' signed int int 2
'I' unsigned int int 2
'l' signed long int 4
'L' unsigned long int 4
'q' signed long long int 8
'Q' unsigned long long int 8
'f' float float 4
'd' double float 8
Array 생성
Array의 인스턴스를 생성하고 인덱스로 조회
Array 변수 : itemsize
Method Description
'itemsize', Array에 구성된 요소들이 메모리 사이즈
Array 이해
list와 array.array 차이점
list와 Array는 sequence data type이지만 처리하
는 기준이 상이
list
array.array
다양한 data type
을 저장하고 처리
단일 typecode를 저
장하고 처리
Array : byte 구성처리
Array를 binary로 변환해서 처리해서 내부 구성을
확인
Array 인덱스/슬라이싱
Array의 인덱스(값)/슬라이싱(일부)를 이용해서 조
회
Array 메소드
Array : append
l = [1,2,3,4] ar = array(‘u', ‘abcdef')
Method List example Array example Description
append(obj) l.append(5)
l
[1, 2, 3, 4, 5]
ar.append(‘g')
ar
array(‘u', ‘abcdefg')
Array 객체에 추가
extend(iterable) l.extend([6,7,8])
l
[1, 2, 3, 4, 5, 6, 7, 8]
ar.extend('abc')
ar
array(‘u', ‘abcdefgabc')
Array 에 시퀀스 타입을 추가
Array : count/index
l = [1,2,3,4] ar = array(‘u', 'helloworld')
Method List example Array example Description
count(obj) l.count(1)
1
ar.count('l')
3
Array 원소에 대한 갯수
index(obj) l.index(2)
1
ar.index('e')
1
Array 내의 원소의 인덱스
Array : insert/pop
l = [1,2,3,4] ar = array(‘u', 'helloworld')
Method List example Array example Description
insert(index,obj) l.insert(2,7)
L
[1, 2, 7, 3, 4]
ar.insert(10,'!')
ar
array(‘u', 'helloworld!')
Array 내에 인덱스 위치에 삽입
pop([i]) l.pop(2)
7
ar.pop()
'c'
ar
array(‘u', 'helloworld')
인덱스가 가르치는 곳에 원소를
삭제, 인덱스가 없으면 제일 끝을
제거
Array : remove/reverse
l = [1,2,3,4], ar = array(‘u', 'helloworld')
Method example Array example Description
remove(obj) l.remove(4)
l
[1, 2, 3]
ar.remove('b')
ar
array(‘u', 'helloworld')
array를 원소의 값으로 제거
reverse() l.reverse()
l
[4, 3, 2, 1]
ar.reverse()
ar
array(‘u', 'dlrowolleh')
array를 반대방향으로 소트
Array : buffer_info
메모리 buffer에 대한 정보를 조회
Method Description
'buffer_info',
Array 주소로 array 정보 불러옴
Array : byteswap
기존 정의된 문자열(unicode, byte)들을 byte를
변경시킴
Method Description
'byteswap', 배열의 모든 항목을 정수 값 지원됩니다. 다른 바이트로 컴퓨터
에 기록 된 파일에서 데이터를 읽을 때 유용합니다.
Array : from/to list
Method Description
'tolist', Array 를 리스트로 전환
'fromlist', List를 Array 내의 원소의 이동
File 처리
Array : fromfile/tofile
Method Description
'fromfile', File에 저장된 값을 Array 에 시퀀스에 추가
'tofile',
배열에 있는 것을 파일에 쓰기
array.array 타입으로 file 처리시 bytes로 처리
해야 함
bytes 처리
Array : from/to bytes
Method Description
'frombytes', byte를 받아 유니코드 array 처리
'tobytes', Array 배열을 byte 타입으로 전달
array.array 타입으로 bytes으로 전환하지 않으
면 데이터가 제대로 변환되지 않음
주의 : ‘u’로 정의
파이썬 3버전은 unicode가 기본이지만
array.array의 “u”로 변환시 출력값이 상이하게
보임
주의 : ‘b’로 정의
파이썬 3버전은 unicode가 기본이지만
array.array의 “b”로 변환해서 처리
문자열 처리
Array: from/to string
Method Description
'fromstring', String을 가져와서 Array 내에 값으로 이동
'tostring', Array 를 스트링으로 전환
array.array 타입으로 string으로 전환하지 않으
면 데이터가 제대로 변환되지 않음
주의 : ‘u’로 정의
파이썬 3버전은 unicode가 기본이지만
array.array의 “u”로 변환시 출력값이 상이하게
보임
주의 : ‘b’로 정의
파이썬 3버전은 unicode가 기본이지만
array.array의 “b”로 변환해서 처리
Unicode 처리
Array: from/to unicode
Method Description
'fromunicode', String을 가져와서 Array 내에 값으로 이동
'tounicode', Array 를 스트링으로 전환
array.array는 bytes 처리이므로 파이썬 3 버전
unicode 일 경우는 이 메소드로 처리

More Related Content

What's hot

Physics spm paper2
Physics spm paper2 Physics spm paper2
Physics spm paper2 Ramli Rem
 
Poultry nutrition and feeding
Poultry nutrition and feedingPoultry nutrition and feeding
Poultry nutrition and feedingMuhammad Eko
 
Bab 9 : Bahan Buatan dalam Industri
Bab 9 : Bahan Buatan dalam IndustriBab 9 : Bahan Buatan dalam Industri
Bab 9 : Bahan Buatan dalam IndustriDianaAmira
 
SLAID PETIKAN SUMBANGAN WIRA NEGARA
SLAID PETIKAN SUMBANGAN WIRA NEGARASLAID PETIKAN SUMBANGAN WIRA NEGARA
SLAID PETIKAN SUMBANGAN WIRA NEGARAmazuramatzain
 
21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenaga
21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenaga21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenaga
21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenagaMrHan Physics
 
Bahan kimia dalam industri
Bahan kimia dalam industriBahan kimia dalam industri
Bahan kimia dalam industriBarbara Sian
 

What's hot (11)

Physics spm paper2
Physics spm paper2 Physics spm paper2
Physics spm paper2
 
Poultry nutrition and feeding
Poultry nutrition and feedingPoultry nutrition and feeding
Poultry nutrition and feeding
 
Tips for answering spm paper
Tips for answering spm paperTips for answering spm paper
Tips for answering spm paper
 
Bab 9 : Bahan Buatan dalam Industri
Bab 9 : Bahan Buatan dalam IndustriBab 9 : Bahan Buatan dalam Industri
Bab 9 : Bahan Buatan dalam Industri
 
5 sistem-tenaga-tingkatan-4
5 sistem-tenaga-tingkatan-45 sistem-tenaga-tingkatan-4
5 sistem-tenaga-tingkatan-4
 
Rph pj mikroteaching
Rph pj mikroteachingRph pj mikroteaching
Rph pj mikroteaching
 
SLAID PETIKAN SUMBANGAN WIRA NEGARA
SLAID PETIKAN SUMBANGAN WIRA NEGARASLAID PETIKAN SUMBANGAN WIRA NEGARA
SLAID PETIKAN SUMBANGAN WIRA NEGARA
 
Inersia
Inersia Inersia
Inersia
 
21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenaga
21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenaga21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenaga
21.kerja,kuasa,tenaga keupayaan,tenaga kinetik,keabadian tenaga
 
F4 -sets
F4 -setsF4 -sets
F4 -sets
 
Bahan kimia dalam industri
Bahan kimia dalam industriBahan kimia dalam industri
Bahan kimia dalam industri
 

Similar to Python array.array 모듈 이해하기

파이썬 문자열 이해하기
파이썬 문자열 이해하기파이썬 문자열 이해하기
파이썬 문자열 이해하기Yong Joon Moon
 
파이썬 문자열 이해하기
파이썬 문자열 이해하기파이썬 문자열 이해하기
파이썬 문자열 이해하기Yong Joon Moon
 
Python+numpy pandas 1편
Python+numpy pandas 1편Python+numpy pandas 1편
Python+numpy pandas 1편Yong Joon Moon
 
파이썬정리 20160130
파이썬정리 20160130파이썬정리 20160130
파이썬정리 20160130Yong Joon Moon
 
Java_02 변수자료형
Java_02 변수자료형Java_02 변수자료형
Java_02 변수자료형Hong Hyo Sang
 
Java 변수자료형
Java 변수자료형Java 변수자료형
Java 변수자료형Hyosang Hong
 
파이썬+데이터+구조+이해하기 20160311
파이썬+데이터+구조+이해하기 20160311파이썬+데이터+구조+이해하기 20160311
파이썬+데이터+구조+이해하기 20160311Yong Joon Moon
 
파이썬+Json+이해하기 20160301
파이썬+Json+이해하기 20160301파이썬+Json+이해하기 20160301
파이썬+Json+이해하기 20160301Yong Joon Moon
 
Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체Circulus
 
Javascript - Array
Javascript - ArrayJavascript - Array
Javascript - Arraywonmin lee
 
배열과 포인터
배열과 포인터배열과 포인터
배열과 포인터영기 김
 
2015 Kitel C 언어 강좌3
2015 Kitel C 언어 강좌32015 Kitel C 언어 강좌3
2015 Kitel C 언어 강좌3ssuseraf62e91
 
C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)
C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)
C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)혜웅 박
 
Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1Park Jonggun
 
Python datatype
Python datatypePython datatype
Python datatype건희 김
 
빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)SeongHyun Ahn
 
Python Programming: Type and Object
Python Programming: Type and ObjectPython Programming: Type and Object
Python Programming: Type and ObjectChan Shik Lim
 

Similar to Python array.array 모듈 이해하기 (20)

파이썬 문자열 이해하기
파이썬 문자열 이해하기파이썬 문자열 이해하기
파이썬 문자열 이해하기
 
파이썬 문자열 이해하기
파이썬 문자열 이해하기파이썬 문자열 이해하기
파이썬 문자열 이해하기
 
Python+numpy pandas 1편
Python+numpy pandas 1편Python+numpy pandas 1편
Python+numpy pandas 1편
 
파이썬정리 20160130
파이썬정리 20160130파이썬정리 20160130
파이썬정리 20160130
 
Java_02 변수자료형
Java_02 변수자료형Java_02 변수자료형
Java_02 변수자료형
 
Java 변수자료형
Java 변수자료형Java 변수자료형
Java 변수자료형
 
파이썬+데이터+구조+이해하기 20160311
파이썬+데이터+구조+이해하기 20160311파이썬+데이터+구조+이해하기 20160311
파이썬+데이터+구조+이해하기 20160311
 
파이썬+Json+이해하기 20160301
파이썬+Json+이해하기 20160301파이썬+Json+이해하기 20160301
파이썬+Json+이해하기 20160301
 
Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체
 
강의자료3
강의자료3강의자료3
강의자료3
 
Javascript - Array
Javascript - ArrayJavascript - Array
Javascript - Array
 
배열과 포인터
배열과 포인터배열과 포인터
배열과 포인터
 
2015 Kitel C 언어 강좌3
2015 Kitel C 언어 강좌32015 Kitel C 언어 강좌3
2015 Kitel C 언어 강좌3
 
C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)
C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)
C프로그래머를 위한 Java 기초 입문 (Java1.5 기준)
 
Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1
 
Python datatype
Python datatypePython datatype
Python datatype
 
[ES6] 12. Array
[ES6] 12. Array[ES6] 12. Array
[ES6] 12. Array
 
빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)
 
Java standard(8~13)
Java standard(8~13)Java standard(8~13)
Java standard(8~13)
 
Python Programming: Type and Object
Python Programming: Type and ObjectPython Programming: Type and Object
Python Programming: Type and Object
 

More from Yong Joon Moon

Scala companion object
Scala companion objectScala companion object
Scala companion objectYong Joon Moon
 
Scala block expression
Scala block expressionScala block expression
Scala block expressionYong Joon Moon
 
Scala self type inheritance
Scala self type inheritanceScala self type inheritance
Scala self type inheritanceYong Joon Moon
 
Scala type class pattern
Scala type class patternScala type class pattern
Scala type class patternYong Joon Moon
 
Scala nested function generic function
Scala nested function generic functionScala nested function generic function
Scala nested function generic functionYong Joon Moon
 
스칼라 클래스 이해하기 _Scala class understanding
스칼라 클래스 이해하기 _Scala class understanding스칼라 클래스 이해하기 _Scala class understanding
스칼라 클래스 이해하기 _Scala class understandingYong Joon Moon
 
파이썬 반복자 생성자 이해하기
파이썬 반복자 생성자 이해하기파이썬 반복자 생성자 이해하기
파이썬 반복자 생성자 이해하기Yong Joon Moon
 
파이썬 프로퍼티 디스크립터 이해하기
파이썬 프로퍼티 디스크립터 이해하기파이썬 프로퍼티 디스크립터 이해하기
파이썬 프로퍼티 디스크립터 이해하기Yong Joon Moon
 
파이썬 플라스크 이해하기
파이썬 플라스크 이해하기 파이썬 플라스크 이해하기
파이썬 플라스크 이해하기 Yong Joon Moon
 
파이썬 내부 데이터 검색 방법
파이썬 내부 데이터 검색 방법파이썬 내부 데이터 검색 방법
파이썬 내부 데이터 검색 방법Yong Joon Moon
 
파이썬 Xml 이해하기
파이썬 Xml 이해하기파이썬 Xml 이해하기
파이썬 Xml 이해하기Yong Joon Moon
 

More from Yong Joon Moon (20)

rust ownership
rust ownership rust ownership
rust ownership
 
Scala namespace scope
Scala namespace scopeScala namespace scope
Scala namespace scope
 
Scala companion object
Scala companion objectScala companion object
Scala companion object
 
Scala block expression
Scala block expressionScala block expression
Scala block expression
 
Scala self type inheritance
Scala self type inheritanceScala self type inheritance
Scala self type inheritance
 
Scala variable
Scala variableScala variable
Scala variable
 
Scala type class pattern
Scala type class patternScala type class pattern
Scala type class pattern
 
Scala match pattern
Scala match patternScala match pattern
Scala match pattern
 
Scala implicit
Scala implicitScala implicit
Scala implicit
 
Scala type args
Scala type argsScala type args
Scala type args
 
Scala trait usage
Scala trait usageScala trait usage
Scala trait usage
 
Scala nested function generic function
Scala nested function generic functionScala nested function generic function
Scala nested function generic function
 
Scala dir processing
Scala dir processingScala dir processing
Scala dir processing
 
Scala syntax function
Scala syntax functionScala syntax function
Scala syntax function
 
스칼라 클래스 이해하기 _Scala class understanding
스칼라 클래스 이해하기 _Scala class understanding스칼라 클래스 이해하기 _Scala class understanding
스칼라 클래스 이해하기 _Scala class understanding
 
파이썬 반복자 생성자 이해하기
파이썬 반복자 생성자 이해하기파이썬 반복자 생성자 이해하기
파이썬 반복자 생성자 이해하기
 
파이썬 프로퍼티 디스크립터 이해하기
파이썬 프로퍼티 디스크립터 이해하기파이썬 프로퍼티 디스크립터 이해하기
파이썬 프로퍼티 디스크립터 이해하기
 
파이썬 플라스크 이해하기
파이썬 플라스크 이해하기 파이썬 플라스크 이해하기
파이썬 플라스크 이해하기
 
파이썬 내부 데이터 검색 방법
파이썬 내부 데이터 검색 방법파이썬 내부 데이터 검색 방법
파이썬 내부 데이터 검색 방법
 
파이썬 Xml 이해하기
파이썬 Xml 이해하기파이썬 Xml 이해하기
파이썬 Xml 이해하기
 

Python array.array 모듈 이해하기

  • 3. Array 생성 규칙 array 클래스를 이용해 동일한 타입값(typecode)으 로 인스턴스를 생성하기 array.array(typecode[, initializer])
  • 4. Array 변수 : type codes array.array 지정 시 타입코드 type code C Type Python Type Minimum size in bytes 'b' signed char int 1 'B' unsigned char int 1 'u' Py_UNICODE Unicode character 2 'h' signed short int 2 'H' unsigned short int 2 'i' signed int int 2 'I' unsigned int int 2 'l' signed long int 4 'L' unsigned long int 4 'q' signed long long int 8 'Q' unsigned long long int 8 'f' float float 4 'd' double float 8
  • 5. Array 생성 Array의 인스턴스를 생성하고 인덱스로 조회
  • 6. Array 변수 : itemsize Method Description 'itemsize', Array에 구성된 요소들이 메모리 사이즈
  • 8. list와 array.array 차이점 list와 Array는 sequence data type이지만 처리하 는 기준이 상이 list array.array 다양한 data type 을 저장하고 처리 단일 typecode를 저 장하고 처리
  • 9. Array : byte 구성처리 Array를 binary로 변환해서 처리해서 내부 구성을 확인
  • 12. Array : append l = [1,2,3,4] ar = array(‘u', ‘abcdef') Method List example Array example Description append(obj) l.append(5) l [1, 2, 3, 4, 5] ar.append(‘g') ar array(‘u', ‘abcdefg') Array 객체에 추가 extend(iterable) l.extend([6,7,8]) l [1, 2, 3, 4, 5, 6, 7, 8] ar.extend('abc') ar array(‘u', ‘abcdefgabc') Array 에 시퀀스 타입을 추가
  • 13. Array : count/index l = [1,2,3,4] ar = array(‘u', 'helloworld') Method List example Array example Description count(obj) l.count(1) 1 ar.count('l') 3 Array 원소에 대한 갯수 index(obj) l.index(2) 1 ar.index('e') 1 Array 내의 원소의 인덱스
  • 14. Array : insert/pop l = [1,2,3,4] ar = array(‘u', 'helloworld') Method List example Array example Description insert(index,obj) l.insert(2,7) L [1, 2, 7, 3, 4] ar.insert(10,'!') ar array(‘u', 'helloworld!') Array 내에 인덱스 위치에 삽입 pop([i]) l.pop(2) 7 ar.pop() 'c' ar array(‘u', 'helloworld') 인덱스가 가르치는 곳에 원소를 삭제, 인덱스가 없으면 제일 끝을 제거
  • 15. Array : remove/reverse l = [1,2,3,4], ar = array(‘u', 'helloworld') Method example Array example Description remove(obj) l.remove(4) l [1, 2, 3] ar.remove('b') ar array(‘u', 'helloworld') array를 원소의 값으로 제거 reverse() l.reverse() l [4, 3, 2, 1] ar.reverse() ar array(‘u', 'dlrowolleh') array를 반대방향으로 소트
  • 16. Array : buffer_info 메모리 buffer에 대한 정보를 조회 Method Description 'buffer_info', Array 주소로 array 정보 불러옴
  • 17. Array : byteswap 기존 정의된 문자열(unicode, byte)들을 byte를 변경시킴 Method Description 'byteswap', 배열의 모든 항목을 정수 값 지원됩니다. 다른 바이트로 컴퓨터 에 기록 된 파일에서 데이터를 읽을 때 유용합니다.
  • 18. Array : from/to list Method Description 'tolist', Array 를 리스트로 전환 'fromlist', List를 Array 내의 원소의 이동
  • 20. Array : fromfile/tofile Method Description 'fromfile', File에 저장된 값을 Array 에 시퀀스에 추가 'tofile', 배열에 있는 것을 파일에 쓰기 array.array 타입으로 file 처리시 bytes로 처리 해야 함
  • 22. Array : from/to bytes Method Description 'frombytes', byte를 받아 유니코드 array 처리 'tobytes', Array 배열을 byte 타입으로 전달 array.array 타입으로 bytes으로 전환하지 않으 면 데이터가 제대로 변환되지 않음
  • 23. 주의 : ‘u’로 정의 파이썬 3버전은 unicode가 기본이지만 array.array의 “u”로 변환시 출력값이 상이하게 보임
  • 24. 주의 : ‘b’로 정의 파이썬 3버전은 unicode가 기본이지만 array.array의 “b”로 변환해서 처리
  • 26. Array: from/to string Method Description 'fromstring', String을 가져와서 Array 내에 값으로 이동 'tostring', Array 를 스트링으로 전환 array.array 타입으로 string으로 전환하지 않으 면 데이터가 제대로 변환되지 않음
  • 27. 주의 : ‘u’로 정의 파이썬 3버전은 unicode가 기본이지만 array.array의 “u”로 변환시 출력값이 상이하게 보임
  • 28. 주의 : ‘b’로 정의 파이썬 3버전은 unicode가 기본이지만 array.array의 “b”로 변환해서 처리
  • 30. Array: from/to unicode Method Description 'fromunicode', String을 가져와서 Array 내에 값으로 이동 'tounicode', Array 를 스트링으로 전환 array.array는 bytes 처리이므로 파이썬 3 버전 unicode 일 경우는 이 메소드로 처리