首页 > 编程语言 > 详细

python分支循环

时间:2019-10-20 16:13:39      阅读:99      评论:0      收藏:0      [点我收藏+]

1.遍历循环

for i in range(5)
for i in range (M,N,K)
for c in s:
for c in python
  print(c,end="")
for i in fi :  #系统打开文件

2.无线循环

while c>0:
    语句块

3.break与continue

break:结束当前循环结构,进入循环体后面的语句(单层)
continue:结束当次循环体后面的内容,继续重新进入循环体

 

s=python
while s != "":
    for c in s:
        print (c,end="")
    s = s[:-1]  #从前面第一关取到最后,但不包括最后一位

#输出结果为:pythonpythopythpytpyp

s=python
while s != "":
    for c in s:
        if c == "T":
            break
        print (c,end="")
    s = s[:-1] 

#输出结果为:pypypypypyp

4.高级循环  循环与else

  else:正常退出循环的“”奖励”,即没有执行break

for(while) :
    <语句>
else:
#语句中若无break,else部分一定会执行
for c in pyYhon:
    if c == t:
        break
    print(c,end = ‘‘)
else:
    print(\n字符串里面没有t)

 

python分支循环

原文:https://www.cnblogs.com/xdd1997/p/11707517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!