I have a string myString
:
myString = "alpha beta gamma"
I want to split myString
into its three words:
myWords = myString.split()
Then, I can access each word individually:
firstWord = myWords[0]
secondWord = myWords[1]
thirdWord = myWords[2]
My question: How can I assign these three words in just one line, as an output from the split()
function? For example, something like:
[firstWord secondWord thirdWord] = myString.split()
What's the syntax in Python 2.7?