Python 获取while语句的输入

Python 获取while语句的输入,python,Python,如何存储用户在上面一行中输入的行的输入。我认为最好让您的while循环如下: while int(input("Input an integer (0 terminates): ")) != 0: #do stuff to the input 最好且更干净的解决方案是创建一个无限循环,并在用户输入0时将其打断: # loop continuously while True: # get the input and store it in the variable inp

如何存储用户在上面一行中输入的行的输入。

我认为最好让您的while循环如下:

while int(input("Input an integer (0 terminates): ")) != 0:
    #do stuff to the input

最好且更干净的解决方案是创建一个无限循环,并在用户输入0时将其打断:

# loop continuously
while True:
    # get the input and store it in the variable inp
    inp = int(input("Input an integer (0 terminates): "))
    # break the loop if inp equals 0
    if inp == 0:
        break
    # do stuff to the input

好吧,这就是我目前拥有的,我只是想优化它,如果这已经是最好的了。我会保留的,谢谢!在输入
0
后,(现在已删除)第一个将再次打印
inp
(或在循环中执行的任何操作)。Mmmh!好眼力。。。然后我把它取下来。我想,
而True
是最好的解决方案。
while True:
    inp = int(input("Input an integer (0 terminates): "))
    if inp == 0:
        break 
    print inp
while 1:
    n = input("Input an integer (0 terminates): ")
    if n == 0:
        break
    # do something with n