꺼내먹는지식 준

Python Flat sequence, Container sequence 본문

카테고리 없음

Python Flat sequence, Container sequence

알 수 없는 사용자 2023. 3. 18. 14:58

파이썬에는 두가지 sequence 가 존재한다. 

 

Container 는 objects 의 reference 를 hold 하는 반면, flat sequence 는 실제 값을 저장한다. 

 

Container sequences: 

list: a mutable sequence that can hold any type of object 

tuple: an immutable sequence that can hold any type of object 

collections.deque: a mutable sequence optimized for adding and removing items from both ends 

 

Flat sequences: 

str: an immutable sequence of Unicode characters 

bytes: an immutable sequence of bytes 

bytearray: a mutable sequence of bytes

 

 

 

Container sequence example

 

이 말인 즉슨, container 는 주소값을 포함하므로 

my_list[0]

와 같이 주소값에 들어가서 수정이 가능하다. 

 

반면, Flat Sequence는 아래와 같이 직접 값을 저장하고 있다. 

 

이에 따라 주소값에 들어가서 값을 수정하는 것이 불가능하다.

 

그러나 id() 라는 기능을 제공하여 string 전체에 대한 특정 interger 값을 제공해줄 수는 있다. 

이는 주소값과 관련 없고, character 을 one by one 지칭하는 것은 아니지만 만약 동일한 string 이 존재한다면 두 string 이 같은 주소에 저장 된 같은 값인지 아닌지 확인할 때 사용할 수 있다. 

Comments