0

How do you split a string into a several strings in python. The string I am trying to split is in the format of:

Variable 1

and I would like to split it into:

Variable = Variable

Number = 1

  • 3
    Do you know that strings have a method called `split`? – mkrieger1 Oct 20 '21 at 15:04
  • 2
    You really need to run through a full Python tutorial or class; this is *very* simple string manipulation; you can't learn the basics piecemeal a StackOverflow question at a time. – ShadowRanger Oct 20 '21 at 15:04

1 Answers1

1

You could split based on the space in the example you gave, unless you need a more generic approach.


# set up your variable
my_var = "variable 1"

# You can split by the space in this instance, if all of your data will look the same
my_split = my_var.split(" ")

# prints variable
print(my_split[0])

# prints 1
print(my_split[1])

syntheticgio
  • 588
  • 6
  • 25