-5

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.

Mazdak
  • 105,000
  • 18
  • 159
  • 188

3 Answers3

1
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.

Amadan
  • 191,408
  • 23
  • 240
  • 301
0

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.

Helios83
  • 87
  • 1
  • 12
0
s = 'insert 0 9'
li= s.split(' ')
var = li[0]
del li[0]

print(var)
insert

print(li)

['0', '9']
LetzerWille
  • 5,355
  • 4
  • 23
  • 26