+ 1

How to exit a program in Python?

I want to exit the program if a condition is false. How can I do that?

31st Jul 2019, 3:34 PM
The Aemogie
The Aemogie - avatar
3 Réponses
+ 3
while not condition: There, if the condition was true before the loop and it becomes false, the loop will break You could also do while True: if condition == False: break
31st Jul 2019, 3:43 PM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar
+ 2
You can also make the program in a function, and use a return statement to break out.
31st Jul 2019, 3:48 PM
Seb TheS
Seb TheS - avatar
+ 1
from sys import exit if CRAP!!: exit()
31st Jul 2019, 5:22 PM
Loeschzwerg