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]: '萌萌哒!' '''

 

posted @ 2017-06-24 15:30  梓林  阅读(1758)  评论(0编辑  收藏  举报