ITPub博客

首页 > Linux操作系统 > Linux操作系统 > What else is there in Python?

What else is there in Python?

原创 Linux操作系统 作者:jieforest 时间:2012-07-25 16:09:01 0 删除 编辑

[size=10.5pt]We all use the else keyword in Python,usually accompanying if statement:

CODE:

if x > 0:
    print 'positive'
elif x < 0:
    print 'negative'
else:
    print 'zero' [size=10.5pt]but Python has a few other uses to the else keyword that mostpeople are unfamiliar with.
for .. else
I bet you didn’t know that you can put an else clause after a for loop! What does it do? When the items you iterator over are exhausted, the else clause is executed. When aren’t the items exhausted? When you use a break statement.


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/301743/viewspace-736618/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: NetBeans 7.2发布
请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    441
  • 访问量
    602345