python之for循环

# for 变量 in iterable: 有限循环

s1 = 'fdksj'
for i in s1:
    print(i+'alex')

#只要循环被break打断,则不执行else程序
#没有被break打断的else
s1 = 'fdksj'
for i in s1:
    print(i)
else:
    print(666)

#被break打断的else
s1 = 'fdksj'
for i in s1:
    print(i)
    if i == 'k':
        break
else:
    print(666)

  

posted @ 2018-10-23 23:56  小菜鸟111  阅读(219)  评论(0编辑  收藏  举报