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

Return statement outside function could do same as exit function - Ideas - Discussions on Python.org
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 return value. More on discuss.python.org
🌐 discuss.python.org
1
May 11, 2021
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
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
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
People also ask

Can I use just 'return' to exit my function?
A: Yes, using just return without a value will exit the function without returning anything (equivalent to returning None).
🌐
sqlpey.com
sqlpey.com › python › top-4-ways-to-exit-a-python-function
Top 4 Ways to Exit a Python Function Without a Return Value …
Can I safely use sys.exit in my function?
A: Yes, sys.exit() can be used, but it’s generally better suited for terminating the entire program rather than just exiting a function.
🌐
sqlpey.com
sqlpey.com › python › top-4-ways-to-exit-a-python-function
Top 4 Ways to Exit a Python Function Without a Return Value …
What should I consider before using os._exit?
A: os._exit() should be used sparingly, primarily in cases where you need to terminate a child process immediately, as it does not clean up the program’s state.
🌐
sqlpey.com
sqlpey.com › python › top-4-ways-to-exit-a-python-function
Top 4 Ways to Exit a Python Function Without a Return Value …
🌐
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
🌐
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…
🌐
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...
🌐
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 :)

🌐
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 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*

🌐
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.
🌐
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)....
🌐
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.
🌐
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.

🌐
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.
🌐
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.
🌐
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.
🌐
Quora
quora.com › How-do-I-get-out-of-a-function-in-Python-using-break
How to get out of a function in Python (using break) - Quora
If you want to very explicitly code that your function returns nothing, you could use return None but this is redundant. ... Atom Registrar Launch Sale! .com $6.75 | .ai $68.00. Use COMLAUNCH or AILAUNCH. 3 .coms or 1 .ai. No hidden fees. ... C, Python, Java, Pascal, C#, VB.net, OpenCV, HTML5, Android · Author has 750 answers and 710.5K answer views · 5y ... RelatedHow can we exit a function in Python and continue with the rest of the code after the function call?
🌐
DataCamp
datacamp.com › tutorial › how-to-exit-python-a-quick-tutorial
How to Exit Python: A Quick Tutorial | DataCamp
April 5, 2024 - In production code, it is common practice to use the sys.exit() function from the sys module to exit Python without relying on the site module. The sys module is generally available but you will need to import it.