Mak*_*aks 5 python goto conditional-statements
由于Python中没有goto运算符,可以使用哪种技术呢?
条件如果是,则转到线程1,如果为false,则转到线程2在线程中我们做一些小事情,之后我们转到线程2,其中所有其他操作都发生.
det*_*tly 14
由于Python中没有goto运算符,可以使用哪种技术呢?
逻辑上和语义上构建代码.
if condition:
perform_some_action()
perform_other_actions()
Run Code Online (Sandbox Code Playgroud)
def thread_1():
# Do thread_1 type stuff here.
def thread_2():
# Do thread_2 type stuff here.
if condition:
thread_1()
# If condition was false, just run thread_2().
# If it was true then thread_1() will return to this point.
thread_2()
Run Code Online (Sandbox Code Playgroud)
编辑:我假设"线程"是指一段代码(也称为子程序或函数).如果您在并行执行中讨论线程,那么您将需要更多详细信息.
| 归档时间: |
|
| 查看次数: |
38717 次 |
| 最近记录: |