标签:while 循环语句 continue aaa class sum nis 控制 als
条件控制语句:if
循环语句:while、for
其他语句:continue、break、pass
# ================================ a = 1 if a < 2: print(‘true‘) else: print(‘false‘) # ================================ if a: print(‘true‘) else: print(‘false‘) # ================================ if a == 0: print(‘a = 0‘) elif a == 1: print(‘a = 1‘) elif a == 2: print(‘a = 2‘) else: print(‘a为其他值‘)
# =================================== a = 1 sum = 0 while a <= 100: sum += sum a += 1 print(‘1到100的和为:‘, sum) # =================================== a = 0 while a < 5: print(‘a小于5‘) a += 1 else: print(‘a大于等于5‘) # =================================== a = 0 while a < 5: a += 1 if a == 2: continue if a == 4: break print(a, end=‘ ‘)
# ================================== lst = [‘aaa‘, ‘bbb‘, ‘ccc‘, ‘ddd‘] for s in lst: print(s, end=‘ ‘) print() # ================================== lst = [‘aaa‘, ‘bbb‘, ‘ccc‘, ‘ddd‘] for s in lst: if s == ‘aaa‘: continue if s == ‘ccc‘: break print(s, end=‘ ‘) else: print(‘finish‘) print()
a = 0 if a == 0: pass elif a == 1: pass elif a == 2: pass else: pass
标签:while 循环语句 continue aaa class sum nis 控制 als
原文地址:https://www.cnblogs.com/wbz-blogs/p/12081559.html