Store multi-line input into a String (Python)

前端 未结 5 1818
鱼传尺愫
鱼传尺愫 2021-02-06 16:28

Input:

359716482
867345912
413928675
398574126
546281739
172639548
984163257
621857394
735492861

my co

5条回答
  •  攒了一身酷
    2021-02-06 16:56

    You can easily create one, using generators. Here is one such implementation. Note you can either press a blank return or any Keyboard Interrupt to break out of the inputloop

    >>> def multi_input():
        try:
            while True:
                data=raw_input()
                if not data: break
                yield data
        except KeyboardInterrupt:
            return
    
    
    >>> userInput = list(multi_input())
    359716482
    867345912
    413928675
    398574126
    
    >>> userInput
    ['359716482', '867345912', '413928675', '398574126']
    >>> 
    

提交回复
热议问题