网站建设资讯

NEWS

网站建设资讯

python流程控制

流程控制if

成都创新互联公司专注于南山企业网站建设,自适应网站建设,商城建设。南山网站建设公司,为南山等地区提供建站服务。全流程按需定制,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

why:选择,或者比大小

what:流程控制语句if

how:

    1,基本语句:

  if   条件:
       代码块

    2,五种情况:

        a,单独if

      if 2>3:
         print(666)

        b,if     else

                name = input('>>>')

                if name == 'ghl'

                print('hehe')

                else:

                print(666)

        c,if elif  elif 

                num = int(input('>>>'))

                if num == 6:

                    print('吃饭')

                elif num == 4:

                    print('回家')

                elif num == 2:

                    print('玩')

        d,if elif  elif  else

                num = int(input('>>>'))

                if num == 6:

                    print('吃饭')

                elif num == 4:

                    print('回家')

                elif num == 2:

                    print('玩')

                else:

                    print('其他')

        e,if 嵌套

                python流程控制

where:逻辑情况出现很多

流程控制语句while:

    why:用到循环的地方

    what:流程控制语句while

    how:

        1,基本结构:

            while 条件:

                循环体

        2,循环举例:

            flag = True

             while flag:

                print(111)

                print(222)

                    flag = False

        3,终止循环

                a,条件不成立

                b,break

                c,系统命令quit()

        break:循环中只要遇到break就直接跳出循环

        continue:遇到continue跳出本次循环,继续下次循环

        while....else.....只要while循环被break打断,则不走else程序

        python流程控制


文章名称:python流程控制
路径分享:http://njwzjz.com/article/pdipoe.html