How to extract the first and final words from a string?

前端 未结 6 1397
鱼传尺愫
鱼传尺愫 2020-12-31 00:49

I have a small problem with something I need to do in school...

My task is the get a raw input string from a user (text = raw_input()) and I need to pri

6条回答
  •  温柔的废话
    2020-12-31 01:11

    If you are using Python 3, you can do this:

    text = input()
    first, *middle, last = text.split()
    print(first, last)
    

    All the words except the first and last will go into the variable middle.

提交回复
热议问题