1. 程式人生 > >【Python基礎】流程控制-while循環

【Python基礎】流程控制-while循環

while

#while循環 ‘‘‘ while 條件判斷: 滿足條件執行的代碼 ... 條件判斷的根本是True和False的判斷 True才會執行 False不會執行 通過一下方法來打印條件是True或者False a = 10 b = 20 print(a > b) print(b > a) ‘‘‘ # 值條件判斷: # a = 3 # b = 5 # 正常條件判斷 # while a > b: # print("啦啦啦") # 死循環 # while True: # print("啦啦啦") #打印1-50數字到終端 ‘‘‘ 方法一: 直接使用條件判斷 ‘‘‘ # count = 1 # while count <=50: # print(count) # count+=1 #其實等同於count=count+1 ‘‘‘ 方法二: 直接修改標簽的方法 ‘‘‘ # condition = True # count = 1 # while condition: # print(count) # count+=1 # if count > 50: # condition = False

【Python基礎】流程控制-while循環