python之-if语句
2015-11-16 16:32
681 查看
if语句用来检验一个条件, 如果 条件为真,我们运行一块语句(称为 if-块 ), 否则 我们处理另外一块语句(称为 else-块 )。 else 从句是可选的。
#!/usr/bin/python # Filename: if.py number = 23 guess = int(raw_input('Enter an integer : ')) if guess == number: print 'Congratulations, you guessed it.' # New block starts here print "(but you do not win any prizes!)" # New block ends here elif guess < number: print 'No, it is a little higher than that' # Another block # You can do whatever you want in a block ... else: print 'No, it is a little lower than that' # you must have guess > number to reach here print 'Done' # This last statement is always executed, after the if statement is executed
elif和
else部分是可选的。一个最简单的有效
if语句是:
if True: print 'Yes, it is true'
本文出自 “千面” 博客,请务必保留此出处http://oslibo.blog.51cto.com/10854638/1713150
相关文章推荐
- python web开发--Django 学习
- 用 Python 和 OpenCV 检测图片上的条形码
- python运算符与用法
- 爬虫-利用urllib爬去网页增加user_agent和proxy(Python)
- [LeetCode]题解(python):057-Insert Interval
- python 字串格式化选项
- Python的Flask开发框架简单上手笔记
- Python标准库学习
- 测试开发Python培训:抓取新浪微博评论提取目标数据-技术篇
- [LeetCode]题解(python):056-Merge Intervals
- 老李分享:开发python的unittest结果输出样式
- Python deque
- 封装BerkeleyDB 2.0
- BerkeleyDB的使用
- PHP、JS、Python,数据库 获取今天是星期几了?[开发篇]
- python url解码
- [原]Python Web部署方式总结
- [LeetCode]题解(python):055-Jump Game
- python琐碎的知识积累,闭包
- Python代码总结