2 problems

Mike Kent mrmakent at cox.net
Fri Jul 7 18:48:15 EDT 2006


symonlandor at gmail.com wrote:
> Hello,Im using Python 2.4.2 and I'm starting a few very basic
> programs,but theres two problems I've not found the answers for.
> My first problem is I need code that will count the number of letters
> in a string and return that number to a variable.

>>> s = "hello"
>>> len(s)
5

> My second problem stems from the first as I need a function that can
> slice the string into letters and have those put in seperate
> strings.Ive tried using the normal [:1],[:2],etc but I need a function
> that can do that a variable amount of times due to the varying number
> of letters in the input.

>>> s = "hello"
>>> list(s)
['h', 'e', 'l', 'l', 'o']

>
> This would be of great help,as python is new to me.

Welcome aboard!




More information about the Python-list mailing list