Print one word from a string in python

前端 未结 6 950
既然无缘
既然无缘 2021-01-14 01:21

How can i print only certain words from a string in python ? lets say i want to print only the 3rd word (which is a number) and the 10th one

while the text length ma

6条回答
  •  盖世英雄少女心
    2021-01-14 01:37

    Take a look at str.split().

    Alternatively, if you're looking for certain things you might try regular expressions instead; that could cope with the filler words changing, even. But if all you care about is word position within the string, then splitting and printing out certain elements of the resulting list would be the most straightforward.

提交回复
热议问题