I have a variable that contains two words separated by a space, and I want to split it into two variables, one for each word. How would I do this?
As an example, my string would be hello there and I want to split it into the variables word1 and word2.
will do this for you. E.g.,
split()is quite versatile, you can also specify other characters to split on. For more information onsplit()see http://docs.python.org/library/stdtypes.html?highlight=split#str.split