Python - How To Split An Input String Into An Array?
I am trying to create a very simple program for averaging numbers. And one part of it involves converting an input string into an array. E.g. average = input() average becomes 'He
Solution 1:
Simply use the split
function :
lst = txt.split(" ")
Solution 2:
separator = " "
average = input()
print average.split(separator)
There is a inbuilt method called split()
which will get your job done , you can pass a separator variable to that method indicating the character you want to split upon However the default value is space
" " itself , averge.split()
would also work fine in your case.
Post a Comment for "Python - How To Split An Input String Into An Array?"