I want to separate numbers and other characters in a string which is entered by user.
example:
str = insert 0 9
I want to store "insert" in another variable and 0,9 in an array.
I want to separate numbers and other characters in a string which is entered by user.
example:
str = insert 0 9
I want to store "insert" in another variable and 0,9 in an array.
str = "insert 0 9"
args = str.split()
cmd = args.pop(0)
args = map(int, args)
cmd
# => "insert"
args
# => [0, 9]
Of course, maybe I misunderstood the question, so it might not fit.
if the use rawinput
to have input from console, you cannot separate string from numbers. what you can do is to get your input as a string, split it with string.split()
and analyze the resulting element to see if his components are numbers or letters, with some if
.
s = 'insert 0 9'
li= s.split(' ')
var = li[0]
del li[0]
print(var)
insert
print(li)
['0', '9']