×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

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:

 
 
Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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