[Tutor] Decision matrix

Jeff Shannon jeff@ccvcorp.com
Thu Feb 13 13:49:21 2003


Erik Price wrote:

> Jeff Shannon wrote:
>
>> Not quite -- a string is a *sequence* of characters.  Lists and 
>> tuples are also sequences.  There's similarities, but also differences. 
>
>
> Oh, I didn't know that.  Thanks for the clarification.  Followup 
> question: which sequence is used for strings?  Or does it not matter. 


The string sequence is used for strings. ;)  Strings are a sequence all 
on their own, which is why you can do things like:

 >>> for char in "I am a string!":
...     print char, ord(char)
...
I 73
  32
a 97
m 109
  32
a 97
  32
s 115
t 116
r 114
i 105
n 110
g 103
! 33
 >>>

In any situation that requires a sequence, you can use a string.  It's 
only situations that require the specific features of a different type 
of sequence (like, say, the ability to sort, which can only be done on 
lists) that you need to convert from one to the other.

Jeff Shannon
Technician/Programmer
Credit International