728x90 반응형 ByteArray2 [Python] Unicode and Python: encode and decode Python에서 encode와 decode: str과 bytesencode : str 에서 bytes 로decode : bytes 에서 str 로 이때 encoding 방식이 필요하며,해당 encoding 방식에 따라 동일한 str 객체라도 다른 bytes 객체로 변환된다.참고로, str 객체가 같은 경우엔 Unicode의 codepoint (=코드값)는 같음.하지만, encoding방식에 따라 대응되는 bytes 객체는 다름.bytes 대신 bytearray 도 가능. 참고 : Unicode에서의 encoding이란Unicode에서 문자열은 일종의 sequence of code points 임. (코드값들의 sequence)이를 저장 및 전송, 또는 메모리에 올리기 위해선 일종의 code unit 으로.. 2024. 1. 16. [Python] bytes and bytearray: Binary Data for Python Python에서 bytes와 bytearray는binary data를 byte 단위 (1byte = 8bit)로 다루는데사용되는 Data Type임.bytes:bytes 는 immutable byte sequence 로서 일종의 byte로 구성된 tuple에 해당 함.byte literal은 다음과 같이 b라는 prefix를 사용함.b'Hello'은 'Hello'라는 문자열에 대한 byte literal을 의미함.문자열에 대한 bytes 이므로 encoding이 사용되며 기본으로 utf8이 사용됨.byte literal과 같이 추후 변경이 되지 않는 binary data를 위한 데이터 타입이 bytes임.bytes 객체를 출력할 경우,utf8인 경우에는 ascii에 해당하는 바이트는 ascii 문자로 출.. 2024. 1. 15. 이전 1 다음 728x90 반응형