for循环:
for i in range()
for i in range(1,101): #range(1,101)只能在python2版本查看,为1-100 i相当于 临时变量 if i % 2 ==1 : #取余 print(i)for i in range(1,101,2): #2,步长 print(i))
显示结果为:1-100 的奇数。
continue:(跳过50-70)
for i in range(100): if i < 50 or i >70 : print(i)for i in range (100): if 50<70: continue else: print(i)
_user="xiaoyanzi"_passwd="meili" username=input("username:") passwd=input("passwd:") if username==_user and passwd==_passwd: print("welome %s login..."%_user) break else: print("invalid username or passwd!")增加for 循环:_user="xiaoyanzi"_passwd="meili"for i in range(3): #循环三次,i相当于临时变量 username=input("username:") passwd=input("passwd:") if username==_user and passwd==_passwd: print("welome %s login..."%_user) break #break终止,跳出 else: print("invalid username or passwd!")