如何在Python 3中使用exit()

问题描述 投票:0回答:2
import sys
import time
start = time.time()

key = input('Type your key:')
x = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
     'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
     '1', '2', '3', '4', '5', '6', '7', '8', '9')

for x1 in x:
    for x2 in x:
        for x3 in x:
            y = (x1+x2+x3)
            print (y) 
            if y == key:
                print('Founded')
                exit()
done = time.time()
elapsed = done - start
print(elapsed)

代码不会停止使用exit(),程序必须完成所有停止的可能性。

python python-3.x exit
2个回答
0
投票

如果您想退出循环并继续执行您的代码(可以通过将exit替换为]

break

0
投票

您需要运行:

sys.exit("Optional Exiting Message")

代替:

exit()

您在Python空闲时使用exit()。

您也可以使用:

pass

# comment it, is it necessary to write code there?
© www.soinside.com 2019 - 2024. All rights reserved.