zoukankan      html  css  js  c++  java
  • 1.7 BeebeebeeMoomoomoo(if...elif...else && for && continue -break-pass && range)

    if...elif...else

    if condition_1:

      statement_block_1

    elif condition_2:

      statement_block_2

    else:

      statement_block_3

    如果 "condition_1" 为 True 将执行 "statement_block_1" 块语句

    如果 "condition_1" 为False,将判断 "condition_2"

    如果"condition_2" 为 True 将执行 "statement_block_2" 块语句

    如果 "condition_2" 为False,将执行"statement_block_3"块语句

    Loop(for && while)

    1、python循环语句的控制结构图

    2、while 

    2.1 while语句的一般形式

    while 条件判断:

      语句

    2.2 while...else

    while 条件判断:

      语句1

    else:

      语句2

    条件为真执行语句1,条件为假执行语句2

    3、for(循环遍历任何序列项目)

    for循环的一般格式如下:

    for <variable> in <sequence>:

      <statements>

    else:

      <statements>

    continue && break && pass

    break:跳出for和while循环

    cotinue:跳出当前循环的剩余语句,继续执行下一次循环

    pass:占位语句

    range 产生数列

    range的一般形式

    range(起始数,结束数,步长)

    例子

     x = range(0,1)
     x
    [0]

  • 相关阅读:
    使用Node.js创建第一个应用
    Node.js安装
    Node.js简介
    c#中的索引器
    ASP.NET常用内置对象(三)Server
    ASP.NET常用内置对象(二)Response
    ASP.NET常用内置对象(一)Request
    利用JDBC工具类 模拟用户登录!
    JDBC工具类完整版!
    用户登录
  • 原文地址:https://www.cnblogs.com/yangyangchunchun/p/7193344.html
Copyright © 2011-2022 走看看