标签:tin ack while循环 for sum tar continue star mil
while循环
#当某个条件成立后,持续循环
#while 条件:
#循环语句(循环体)
‘‘‘
def sumSum(star,end,step):
i = star
sum = 0
while i<=end:
sum += i
i += step
return sum
print(sumSum(1,10,1))
‘‘‘
#死循环,内存填充,监控异常等用处
‘‘‘
while True:
pas = input(‘请输入密码:‘)
if pas == ‘123‘:
print(‘输入密码正确!‘)
break
print(‘你输入的密码错误!‘)
‘‘‘
for循环
#for循环
nameList = [‘milk‘,‘jack‘,‘mary‘]
index = 0
while index < len(nameList):
print(nameList[index])
index += 1
print(‘for循环:‘)
for name in nameList:#遍历循环
print(name)
for name in range(0,len(nameList)):
print(nameList[name])
for one in range(1,10):#遍历循环数值
print(one)
break语句
跳出本层循环语句!
continue语句
结束本次循环!
注释
#、‘’‘内容’‘’、ctrl+/
def sum():
‘‘‘
备注信息
‘‘‘
return 1
print(sum.__doc__)
标签:tin ack while循环 for sum tar continue star mil
原文地址:https://www.cnblogs.com/wanguku/p/10261874.html