当前位置: 首页 > 后端技术 > Python

Python自学笔记--循环语句、range()函数、pass语句

时间:2023-03-26 16:21:49 Python

斐波那契数列a,b=0,1whileb<10:print(b)a,b=b,a+b112358end关键字用于在同一行输出结果,或者在输出的末尾添加不同的字符c,d=0,1whiled<1000:print(d,end=',')c,d=d,c+d1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,while,else语句count=0whilecount<5:print(count,"小于5")count=count+1else:print(count,"大于等于5")0小于51小于52小于53小于54小于55大于等于5for语句语言=["C","Java","Php","Python"]forxinlanguages:print(x)CJavaPhpPythonrange()函数遍历数字序列,结合len()函数foriinrange(10):print(i)print("-------------------")foriinrange(0,10,2):print(i)print("--------------------")a=['Google','百度','Runoob','淘宝','QQ']foriinrange(len(a)):print(i,a[i])0123456789-----------------02468--------------------0Google1Baidu2Runoob3Taobao4QQpassstatementpassisan空语句,为了保持程序结构的完整性pass什么都不做,一般用于PlaceholderStatement参考:Python3LoopStatement|新手教程