Adarsh Rao
Adarsh Rao

Reputation: 381

How do I split a word into individual letters in Python 2.7

I have a number that I have converted into a string. I now want to assign each of the digits of this number to a new variable that I want to use later. How do I do it?

For example if

input = "98912817271"

How do I assign the one's digit, 1, to a variable 1 and so on?

I've tried searching for a solution but couldn't find any on StackOverflow.Any help would be much appreciated.

Upvotes: 0

Views: 1258

Answers (2)

peanutsee
peanutsee

Reputation: 100

Try this:

def string_spliter(s):
    result = []
    for element in s:
        result.append(element)
    return result

print(string_spliter(string))

Upvotes: 0

Juan de la hoz
Juan de la hoz

Reputation: 106

in python, words are already lists, this means, they already have positions asigned, try: print input[0] and see if you want to assign a variable the value of any position in your string, just select the position as if it was a list: foo = input[#]

Upvotes: 2

Related Questions