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

2
  • 3
    Do you know that strings have a method called split? Commented Oct 20, 2021 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. Commented Oct 20, 2021 at 15:04

1 Answer 1

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])

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.