You can easily break the line into spaces, but if your line does not have enough words, the assignment will fail if the list is empty.
a, b, c, d, e = my_string.split()[:5]
Youβd better keep the list, rather than give each member an individual name.
words = my_string.split() at_most_five_words = words[:5]
This is a terrible variable name, but I used it to illustrate the fact that you are not guaranteed to get five words - you are guaranteed only five words.
kojiro
source share