python学习9-语句
2016-04-11 20:55
525 查看
选择表达式
1.逻辑表达式
and ,or , no
相当于c++的&&,||,!
即与,或,非
2.语句
3.bool类型
只有两个结果:True和False
0,空格,空列表,空字符是False,其他都是True。
4.for循环
5.while循环
6.控制循环
contnue 和break控制循环
这里需要注意的是:continue是调到循环体顶部进行循环,而break是跳出了for循环语句。
1.逻辑表达式
and ,or , no
相当于c++的&&,||,!
即与,或,非
2.语句
if.... elif.... elif.... else...
3.bool类型
只有两个结果:True和False
0,空格,空列表,空字符是False,其他都是True。
4.for循环
values=[1,2,3,4,5,6,7,87] for i in range(len(values))
5.while循环
whie condition: block
6.控制循环
current_line=1 earth_line=0 file=open('data.txt','r') for line in file: line=line.strip() if line=='earth': earth_line=current_line current_line+=1 print 'earth is at line %d' %earth_line
contnue 和break控制循环
entry_number=1 file=open('data.txt','r') for line in file: line=line.strip() if line.startswith('#'): #避开注释行产生的错误,也就是注释行的词语不再搜索范围之内 continue #continue是退出后面的语句,重新进入for语句 if line=='earth' break #跳出for循环 entry_number=entry_number+1 print 'earth is the %dth-lightest planet.' %(entry_number)
这里需要注意的是:continue是调到循环体顶部进行循环,而break是跳出了for循环语句。
相关文章推荐
- python笔记 - 高级属性(20160411)
- Python2.7 smtplib发送带附件邮件报错STARTTLS解决方法
- Python2.7 smtplib发送带附件邮件报错STARTTLS解决方法 推荐
- python 模拟登录
- 机器学习/数据挖掘学习资源
- python命令行自动补全
- python小模块学习---filecmp 文件比较
- python模块学习————os
- Python args kwargs
- Python爬虫学习系列教程
- 【自己总结】Sublime2编译Python程序EOFError:EOF when reading a line解决方法
- Python Tutorial
- python学习笔记1
- Python常用的爬虫技巧
- Python urllib简单使用
- python的numpy和matplotlib包的安装
- 用Python计算MIC值
- 执行python脚本报错No module named requests解决方法
- python发布及调用基于SOAP的webservice
- python学习8