安装一个模块:goto-statement
pip3 install goto-statement`
导入goto模块
使用@with_goto修饰为函数整个goto能力
label .xxx,增加标签,标签需要以“.”开头
goto .xxx,跳转到指定的标签处
示例代码:
from goto import with_goto
@with_goto
def Test():
label .start
print('start...')
label .step1
print('step1')
label .step2
print('step2')
goto .start
方法来自:https://steemit.com/cn/@brysj22952/python-goto-learn-for-python-goto-statement