-1

Say for example you have a variable with a string which contains x = '2 C', meaning 2 of clubs.

Is there a way of extracting the string (c) and storing it in a variable, i.e. string_var.

Then extract the number (2) into a different variable, i.e. number_var.

Sam H
  • 118
  • 11
  • Is that structure permanent? Can there NOT be a space between them? Can they be in the reversed order? And most importantly, what have **you** tried to solve your problem? – Tomerikoo May 18 '20 at 18:25
  • I have tried to find the number in the string then I tried to remove from the string using var.remove() method but that didn’t work. My questions has now been answered – Sam H May 18 '20 at 18:28

1 Answers1

1

That's possible, you just need to spilt the string:

x = '2 C'
y = x.split() # returns ["2", "C"]
number = y[0] # do int(y[0]) if you want it to be an int
card_type = y[1]

All that did was split the variable x by a space, then store the output in variables.

xilpex
  • 3,097
  • 2
  • 14
  • 45