美文网首页python学习笔记
第六章:循环语句

第六章:循环语句

作者: 运柱 | 来源:发表于2018-01-23 16:40 被阅读0次

1)python提供了while  else语句

eg:

count = 0

while count < 5:

       print (count, " 小于 5")

      count = count + 1

else:

       print (count, " 大于或等于 5")

2)for循环也提供了else语句

eg:

sites = ["Baidu", "Google","Runoob","Taobao"]

for site in sites:

      if site == "Runoob":

            print("菜鸟教程!") 

           break

      print("循环数据 " + site)

else:

      print("没有循环数据!")

print("完成循环!")

3)python用range来实现c的for语句结构

eg:

for i in range(0, 10, 2):

      print(i, end=",")

4)python的pass语句是空语句,是为了保持程序结构的完整性,仅是占位语句,不做任何事。在循环,函数,和类中使用。

相关文章

网友评论

    本文标题:第六章:循环语句

    本文链接:https://www.haomeiwen.com/subject/ezwsaxtx.html