开发者社区> 问答> 正文

IF语句完成后,如何阻止代码继续进入特定部分?

我有多个IF要执行的语句,但是一旦满足任何IF语句的逻辑,我希望代码跳过任何IF`语句中未包含的特定部分。

当前如何设置代码:

if 1 in df.index:
        if df.col1.isnull()[1] or (df.col1[1]==''):
           [rest of the code]

 if 2 in df.index:
        if df.col1.isnull()[2] or (df.col1[2]==''):
           [rest of the code]

 if 3 in df.index:
        if df.col1.isnull()[3] or (df.col1[3]==''):
           [rest of the code]

展开
收起
安忆333 2019-12-02 17:23:27 923 0
1 条回答
写回答
取消 提交回答
  • 第一个使用if语句,后面的使用elif

    if 1 in df.index:
            if df.col1.isnull()[1] or (df.col1[1]==''):
               [rest of the code]
    
     elif 2 in df.index:
            if df.col1.isnull()[2] or (df.col1[2]==''):
               [rest of the code]
    
     elif 3 in df.index:
            if df.col1.isnull()[3] or (df.col1[3]==''):
               [rest of the code]
    
    2019-12-02 17:25:31
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载