[Tutor] Why difference between printing string & typing its object reference at the prompt?
Alan Gauld
alan.gauld at btinternet.com
Thu Oct 11 09:54:53 CEST 2012
On 11/10/12 02:23, boB Stepp wrote:
>> bytes have string methods as a convenience, such as find, split, and
>> partition. They also have the method decode(), which uses a specified
>> encoding such as "utf-8" to create a string from an encoded bytes
>> sequence.
>
> What is the intended use of byte types?
One purpose is to facilitate the handling of raw data streams such as
might be read from a binary file or over a network. If you are using
locale settings with 16 bit characters reading such a stream as a
character string will result in you processing pairs of bytes at a time.
Using a byte string you guarantee you process 8 bits at a time with no
attempt at interpretation.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list