python流程控制

流程控制if
python

why:選擇,或者比大小ide

what:流程控制語句ifui

how:spa

    1,基本語句:orm

  if   條件:
       代碼塊

    2,五種狀況:
input

        a,單獨if
it

      if 2>3:
         print(666)

        b,if     else
class

                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 嵌套

                QQ截圖20181013191208.png

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程序

        QQ截圖20181013200011.png

相關文章
相關標籤/搜索