When running a script from the command line, why do I need "sys.exit()"? Can anyone please explain this to me with an example? Python documentation can be a bit hard to read sometimes, at least for me 😅
a = int(input())
b = int(input ())
print("Error: You can't divide by zero. we will force to close the program, sorry...")
# Do something if everything is ok...
Ok, good example, doesn't Python finish executing the program anyway? Why is it necessary to write "sys.exit()", to make it explicit? (Sorry for my insistence, but I can't find the answer, I guess it's too basic for Stackoverflow 😅)
Ahhh, ok, so I don't HAVE to use it, I CAN use if for whatever reason it's useful for my goal to exit the script, it's just another tool...
Thank you Rolando for your answers and for your patience!!! I really appreciate it 👍😃
A slightly more technical example: You are from a Shell and want to run a Python script, but you need to know if everything went well. One way to know if everything was executed correctly is to see some value that your script returns. Not only can you go out with sys.exit (), you can also go out with a custom value like sys.exit (1) or sys.exit (999) and use that value returned by your program to do one or another action from your shell.