How do I read multiple lines of raw input in Python?

后端 未结 9 1585
礼貌的吻别
礼貌的吻别 2020-11-22 09:28

I want to create a Python program which takes in multiple lines of user input. For example:

This is a multilined inp         


        
9条回答
  •  醉话见心
    2020-11-22 10:13

    sentinel = '' # ends when this string is seen
    for line in iter(raw_input, sentinel):
        pass # do things here
    

    To get every line as a string you can do:

    '\n'.join(iter(raw_input, sentinel))
    

    Python 3:

    '\n'.join(iter(input, sentinel))
    

提交回复
热议问题