So lets say I have a string come in like this:
newData = "[Fruit]Apple"
How would I set set these variables from the string that was sent in?
type = "Fruit"
food = "Apple"
So lets say I have a string come in like this:
newData = "[Fruit]Apple"
How would I set set these variables from the string that was sent in?
type = "Fruit"
food = "Apple"
replace
and split
:
type, food = newData.replace('[','').split(']')
Or without replace
(credit @Bakuriu), with slicing:
type, food = newData[1:].split(']')
You can use .split()
food = newData.split(']')[-1]
type = newData.split(']')[0].split('[')[-1]