您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python是否正式支持在循环后重用循环变量?

python是否正式支持在循环后重用循环变量?

是的,这是官方的:

for_stmt ::=  "for" target_list "in" expression_list ":" suite
              ["else" ":" suite]

> The target list is not deleted when the loop is finished

http://docs.python.org/reference/compound_stmts.html#for

请注意,后面的目标列表for远不只是变量:

for some_list[blah] in...
for some_object.foo in...
for a[:n] in ...:

等。这些事情不能在循环之后简单消失。

python 2022/1/1 18:41:43 有275人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶