Я знаю, что в функции вы можете выйти из функции, используя return
,
def function():
return
, но вы можете выйти из родительской функции из дочерней функции?
Пример:
def function()
print("This is the parent function")
def exit_both():
print("This is the child function")
# Somehow exit this function (exit_both) and exit the parent function (function)
exit_both()
print("This shouldn't print")
function()
print("This should still be able to print")
Я пытался поднять Exception
, как подсказывает этот ответ , но это просто завершает всю программу.