简体   繁体   中英

Input() to Allow <Enter Key> to Insert New Line Instead Of Returning Out of the Code in Python 3.x

I am new to Python so please explain any code you write!

I want an input() to terminate after 1 blank line to allow for more than one line.

For example, if I press Enter while using input() , I want it to go onto the next line, but if I press Enter again, it returns out of the program.

Try this:

quit = False

while not quit:
    d = input()
    print(d)
    if d == '': quit = True

or

while True:
    d = input()
    if d == '': break
    print(d)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM