Search code examples
pythonstringint

How to convert string consisted of several numbers with a space into a list of integer values of that same string?


I have a string that consists of numbers with a space.

myString = "3 45 12"

I want to make a list of integer values derived from that string, ex:

myList = [3, 45, 12]

Solution

  • Try this:

    myString = "3 45 12"
    numericdata = myString.split(' ')
    numbers = []
    
    for i in numericdata:
        numbers.append(int(i))
    
    print(numbers)