开发者社区> 问答> 正文

多重嵌套循环在Python问题,怎么解决

多重嵌套循环在Python问题,怎么解决

展开
收起
游客ahv54x37wvm7u 2021-10-30 17:21:11 501 0
1 条回答
写回答
取消 提交回答
  • 使用自定义异常可以跳出深层嵌套循环、看我做过的例子: class FoundException(Exception): pass try: for row,record in enumerate(table): for columu,field in enumerate(record): for index,item in enumerate(field): if item == target: raise FoundException() except FoundException: print ("found at ({0},{1},{2})".format(row,column,index)) else: print ('not found')

    2021-10-30 17:21:30
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载