6.Python基础 循环
2015-08-05 22:09
597 查看
根据vamei前辈的博客学习:
/article/4673209.html
for x in ..., for x in range (y), while, break, continue
/article/4673209.html
for x in ..., for x in range (y), while, break, continue
#!/usr/bin/env python ############# for ######################## i = 0 for a in [12, 'hello', 2.22, "精忠报国"]: #注意此处有冒号: print ("for:", i,"->:",a) i = i + 1 #结果: #0 ->: 12 #1 ->: hello #2 ->: 2.22 #3 ->: 精忠报国 ############## range() ####################### for idx in range(10): #注意此处有冒号:,idx是0->9整型数字 print ("range()->:", idx**2) #打印0->9的平方 ############### while ###################### j = 0 while j < 10: print ('while->:', j) j = j + 2 ############### break ##################### for i in range(20): if i == 5: break; #当i等于5时,跳出for循环,循环结束 print ('break->:', i) ############# continue ################### for i in range(10): if i < 5: continue #i<5为true时,继续循环,不再执行下面的语句 else: print ('continue->:', i)上面程序保存为.py文件,按F5编译。
相关文章推荐
- machine learning in coding(python):使用xgboost构建预测模型
- python正则表达式
- python3之if与语句
- 5.Python基础 缩进与选择的关系
- Python之正则表达式
- 用python写MapReduce函数
- 使用Python开发windows桌面程序
- Python文档中if __name__ == '__main__'
- Python使用小技巧
- 简单性能测试: bottle vs flask
- Python列表去重
- TabError: Inconsistent use of tabs and spaces in indentation
- 如何像Python高手(Pythonista)一样编程
- Ubuntu上安装python开发环境pycharm
- Data manipulation primitives in R and Python
- 【Python】读取命令行参数、在PyDev中设置Python运行时的参数
- python argparse
- python 调用短信接口
- python urllib2, urllib使用
- python 绘图