In article <mailman.2172.1277594845.32709.python-l...@python.org>,
Terry Reedy  <tjre...@udel.edu> wrote:
>On 6/26/2010 2:55 PM, Peter Kleiweg wrote:
>>
>> Some basic text string functions seem to be working on byte
>> string functions as well, but sometimes they don't, and there's
>> no rhyme in why it does or doesn't.
>>
>>      >>>  'abcd'[0] == 'abcd'[:1]
>>      True
>>      >>>  b'abcd'[0] == b'abcd'[:1]
>>      False
>>
>> Why????
>
>The bytes behavior is the normal behavior for sequences. Indexing 
>produces an element of the sequence (in this case an int) while slicing 
>produce a subseqeunce of the sequence, which is different from an 
>element of the sequence. Try the same with tuples, lists, and ranges.
>
>Strings are anomalous in that indexing produces a subsequence instead of 
>an element (char in this case, which Guido chose for Python not to have).

Quoting myself from some time back:

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
http://mail.python.org/pipermail/python-3000/2006-April/000897.html
-- 
Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to