zoukankan      html  css  js  c++  java
  • Python流程控制 if / for/ while

    在Python中没有switch语句

    If语句

    if condition:

    do sth

    elif condition:

             Do sth

    else:

             Do sth

    while语句有一个可选的else从句

    while condition:

             do sth

    else:

             do sth

    for循环

    for i in range(1, 5):     # 即序列[1, 2, 3, 4]

    print i

    else:

    print 'The for loop is over'

    break语句

    如果你从for或while循环中 终止 ,任何对应的循环else块将不执行。

    try..except语句处理异常

    import sys

    try:

    s = raw_input('Enter something --> ')

    except EOFError:

    print ' Why did you do an EOF on me?'

    sys.exit() # exit the program

    except:

    print ' Some error/exception occurred.'

    # here, we are not exiting the program

    print 'Done'

     可以使用raise语句 引发 异常,相当于java中的throw

  • 相关阅读:
    观众查询界面
    排球积分程序
    产品会议
    本周工作量及进度统计
    排球积分规则
    我与计算机
    排球记分员
    怎样成为一个高手观后感
    第十八周冲刺
    十六周
  • 原文地址:https://www.cnblogs.com/manhua/p/3843722.html
Copyright © 2011-2022 走看看