TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

What else is there in Python?

14 点作者 Nurdok将近 13 年前

1 comment

dudus将近 13 年前
I agree that the use of else on for and while clauses is very not intuitive. It would be far better if the else would be executed if the list you're iterating over is empty and thus the for/while clause is never ran not even once.<p>So you could rewrite:<p><pre><code> last_val = None for item in myList: last_val = item </code></pre> to:<p><pre><code> for item in myList: last_val = item else: last_val = None</code></pre>
评论 #4284431 未加载