Print one word from a string in python

前端 未结 6 883
既然无缘
既然无缘 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:51

    How about this one:

    import re
    
    tst_str = "You have 15 new messages and the size is 32000"
    items = re.findall(r" *\d+ *",tst_str)
    for item in items:
        print(item)
    

    Result:

     15 
     32000
    

提交回复
热议问题