[Tutor] help (Splitting a word into letters)

David Rock david at graniteweb.com
Tue Mar 18 16:34:47 CET 2014


* y j <yashpanv at gmail.com> [2014-03-18 16:41]:
> how can i split a word into letters in python 2.7.6?

Strings can already be accessed as arrays:

>>> s='foobar'
>>> print s[2]
o
>>> print s[4]
a
>>> print s[7]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  IndexError: string index out of range
>>> 

Can you be a little clearer what you need?  Are you looking to store
them in variables, an array, print them?  If printing them, are you
looking to output one per line, or spaced out?

-- 
David Rock
david at graniteweb.com


More information about the Tutor mailing list