What Does It Mean Program Exited With Code 0 in Python?

For every Python program, when we execute the code, Python will return the code to understand the status of the program execution once the execution is complete. The program will be terminated once all the lines in the program are executed. “program exited with code 0” means the code is successfully executed and the program has no errors.

What are the Three Python Status Codes?

  • exit(0) – The program has no errors and the operation completed successfully
  • exit(1) – There are some issues in your code
  • exit(-1) – User interruped the flow of the execution. In this case, Python interpreter doesn’t know anything about the execution results as the operation was aborted in the middle of run.

What is Program Exited With Code 1 in Python?

If you have any errors in your code, the program will terminate the execution and return status code 1 along with the information about the issues. Below, is the example.

Example

number = '5'
print(number - 1)

Output

TypeError: unsupported operand type(s) for -: 'str' and 'int'

Process finished with exit code 1

What is Program Exited With Code 0 in Python?

If there are no errors in the code, the program will run successfully and return the output with status code 0. If the status code is 0, you needn’t debug your code.

Example

number = '5'
number = int(number)  # convert the string into an integer
print(number - 1)

Output

4

Process finished with exit code 0

What is Program Exited With Code -1 in Python?

This is a very rare scenario that happens only when you use code editors such as PyCharm. If you use the command-line interface to run a code, you won’t see such errors. This code indicated that the program is terminated abnormally either by the user or by any other external or internal factors.

Example 1

import time

number = '5'
number = int(number)  # convert the string into an integer
time.sleep(10) # wait for 10 seconds
print(number - 1)

Output

KeyboardInterrupt

Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)

Example 2

import requests

res = requests.get('https://www.google.com')

Output

I stopped the program by using the stop button in the PyCharm editor and so the interpreter returned the status code -1.


Process finished with exit code -1