You must first convert the string to a list
words using str.split
, and then you can access it, for example:
>>> my_str = "Hello SO user, How are you" >>> word_list = my_str.split()
From Python 3.x, you can simply:
>>> first, *middle, last = my_str.split()
source share