python中程序如何获取实现多行输入
使用迭代器实现多行输入的获取:
1 from functools import partial 2 inputNew = partial(input,'Input something pls:\n') 3 sentinel = 'end' # 遇到这个就结束 4 lines = [] for line in iter(inputNew, sentinel): 5 lines.append(line) 6 7 ''' Input something pls: 8 萌 9 Input something pls: 10 萌 11 Input something pls: 12 哒 13 Input something pls: 14 ! 15 Input something pls: 16 end 17 18 In [20]: ''.join(lines) 19 Out[20]: '萌萌哒!' '''