-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
  • 100,514
  • 17
  • 155
  • 179

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
  • 179,482
  • 20
  • 216
  • 275
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
  • 4,750
  • 3
  • 21
  • 25