You could simply use

return

which does exactly the same as

return None

Your function will also return None if execution reaches the end of the function body without hitting a return statement. Returning nothing is the same as returning None in Python.

Answer from Sven Marnach on Stack Overflow
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python exit function
How to Exit a Function in Python | Delft Stack
February 2, 2024 - If it matches, we print the value of the name variable and then exit the function; otherwise, if the string doesnโ€™t match, we will simply exit it without doing anything. Here, you might think that since there is no return statement written in the code, there is no return statement present. Note that the return statement is not compulsory to write. Whenever you exit any Python function, it calls return with the value of None only if you have not specified the return statement.
Discussions

How to get out function in Python?
We can't help you without seeing your current code. More on reddit.com
๐ŸŒ r/learnpython
4
1
January 5, 2020
How do I exit the program without exit()?
exit() is only required if you need to exit prematurely. For example, this "hello world" script exits just fine: print("Hello World") So of you're not allowed to use exit(), then just write your script in such a way as there's nothing left to run once an exit should occur. More on reddit.com
๐ŸŒ r/learnpython
22
16
April 17, 2015
Can I stop a function from another function?
It is definitely possible, as other people have pointed out, but maybe not necessary, depending of what you intend to do. Could you elaborate more on what exactly you want to do? Like, what exatcly does function 'A' and 'B' does, and what kind of input is this. More on reddit.com
๐ŸŒ r/learnpython
26
66
November 9, 2021
Exiting a program without exit(), quit(), raise SystemExit, etc...
Why do you need an exit function? Use flow control to force the program to exit gracefully when the correct logical conditions exist. Think of it like gravity and your code naturally wants to get to the bottom where it will exit automatically. Think of it as though certain conditions will send your code up the hill, but inevitably it will no longer have any reason to stay higher on the hill, and be forced to reach the bottom. Sorry if this analogy is a bit contrived, I've had a few beers, and I'm watching snow fall on my favorite ski resorts for the first time in months. More on reddit.com
๐ŸŒ r/learnpython
5
2
October 10, 2021
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
Return statement outside function could do same as exit function - Ideas - Discussions on Python.org
May 11, 2021 - statement return x outside a function could have same effect as exit(x) This would be intuitive, because exit makes program end its execution and return value same way like return makes function end its execution andโ€ฆ
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-31275.html
Return not exiting function??
Hello, I have this simple example where I simple want to exit a function when i == 5. def foo(i): print i, "--" if i
๐ŸŒ
YouTube
youtube.com โ€บ low orbit flux
Python - How To Exit A Function - YouTube
https://low-orbit.net/python-how-to-exit-a-functionBuy me a coffee: https://buymeacoffee.com/low_orbit_flux Supplies: https://low-orbit.net/suppliesPython...
Published ย  October 10, 2021
Views ย  3K
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to get out function in python?
r/learnpython on Reddit: How to get out function in Python?
January 5, 2020 -

Guys I am building a Billing Program(Project). I am a beginner and am coding this project on python using functions. I am using different functions for Menu and Veg non veg beverages etc...So first the Menu is printed and then the User Selects what he wants . But when he clicks Veg or Beverage Menu(for example) I display all the items on the respective Menu including option to exit. But I cannot exit or terminate the function using return. Can anyone suggest how to get out of the function and again return the Main-menu using return or break*

๐ŸŒ
Quora
quora.com โ€บ How-do-I-return-value-from-the-function-without-exiting-from-the-function
How to return value from the function without exiting from the function - Quora
Answer (1 of 3): Use global variables. Make a variable in either of the classes, if both the functions are in different in classes. Initialise it. Use the second function to update it and use it any other function. This way you can use the function to change multiple variable values too. There...
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ exit() in python
exit() in Python - Scaler Topics
May 4, 2023 - The sys.exit() function is responsible for throwing the SystemExit exception. To avoid being unintentionally caught by code that catches the exception, it inherits from BaseException rather than the exception.
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how do i exit the program without exit()?
r/learnpython on Reddit: How do I exit the program without exit()?
April 17, 2015 -

The exit() function is not allowed in this task, and I've tried everything in the little Python knowledge I have to exit the function where I want it to.

def ask_if_continue():

cont = raw_input("Do you wish to continue? Type 'y' for yes, 'n' for no:")
if cont == "y":
    print ("You have chosen to continue.")
else:
    print ("You have chosen not to continue.")
return cont

So, as shown, the program needs to exit after the user inputs 'n' and the 'You have chosen not to continue' afterwards. What it does now is go on to the next lines of code regardless of whether I type 'y' or 'n', obviously.

Perhaps enclosing each message in separate functions would help? I think that's part of the task but I'm not 100% sure.

Can anyone help this Python newbie out? Help is much appreciated :)

๐ŸŒ
Python Guides
pythonguides.com โ€บ python-exit-command
Exit Function in Python
October 6, 2025 - The os._exit() function is a lower-level exit command that immediately terminates the Python process without running cleanup handlers, flushing buffers, or raising exceptions.
๐ŸŒ
pythontutorials
pythontutorials.net โ€บ blog โ€บ getting-out-of-a-function-in-python
How to Exit a Python Function Without Using Return: Handling Exceptions Effectively โ€” pythontutorials.net
Returning None might lead to bugs if the caller forgets to check for it. Exceptions force attention: if unhandled, they crash the program with a clear error message, making debugging easier. Exceptions work seamlessly with finally blocks, ensuring resources (e.g., files, network connections) are cleaned up even when exiting abruptly. In Python, raising an exception causes the function to exit immediately.
๐ŸŒ
sqlpey
sqlpey.com โ€บ python โ€บ top-4-ways-to-exit-a-python-function
Top 4 Ways to Exit a Python Function Without a Return Value โ€ฆ
December 5, 2024 - For deeper insight into function ... your thoughts or pose questions on this topic in the comments below! A: Yes, using just return without a value will exit the function without returning anything (equivalent to returning None)....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ can i stop a function from another function?
r/learnpython on Reddit: Can I stop a function from another function?
November 9, 2021 -

Hi guys I'm pretty new in python and I'm doing some exercises. In one of that needs to stop the whole program when one thing happen.
I would like to know if it is possibile to stop a function when something happen in another function.

My function 'B' stop when the user insert in input a specific value, the function 'A' that has to stop at the same time, doesn't.

๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ python-exit-commands-quit-exit-sys-exit-os-exit-and-keyboard-shortcuts
Python Exit Commands: quit(), exit(), sys.exit(), os._exit() and Keyboard Shortcuts | Codecademy
This function prints numbers from 1 to 20 but exits gracefully when it reaches 10, returning a status code of 0 (indicating successful completion). While sys.exit() ensures proper handling, os._exit() is a lower-level function that forces immediate termination without executing cleanups. Letโ€™s examine it next. When a Python program needs to terminate instantly, bypassing all cleanup routines and exception handling, os._exit() is the go-to command.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-exit-commands-quit-exit-sys-exit-and-os-_exit
Python exit commands: quit(), exit(), sys.exit() and os._exit() - GeeksforGeeks
December 31, 2019 - os._exit() method in Python is used to exit the process with specified status without calling cleanup handlers, flushing stdio buffers, etc. Note: This method is normally used in child process after os.fork() system call.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-exit-how-to-use-an-exit-function-in-python-to-stop-a-program
Python Exit โ€“ How to Use an Exit Function in Python to Stop a Program
June 5, 2023 - In this example, the program will print "Before exit", but when the exit() function is called with a status of 1, the program will terminate immediately without executing the remaining code.
๐ŸŒ
Peerlist
peerlist.io โ€บ blog โ€บ engineering โ€บ python-exit-function
How to Use an Exit Function in Python to Stop a Program
Here's how you can use the exit() function: ... The exit() function can take an optional argument, which serves as the exit status code. By default, it returns 0, indicating successful termination.