Python code to exit program

By IncludeHelp Last updated : February 9, 2024

In Python, to exit a program, you can use the sys.exit() method by passing 0 or any other error code.

Below is the source code to exit a Python program:

Python code to exit program

# Importing sys module
import sys

# Main code
print("Hello, World!")

# Exiting the program
sys.exit(0)

Print("Bye Bye")

Output

Hello, World!

To understand the above code, you should have the basic knowledge of the following Python topics:

 
 

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.