Python005条件分支语句
2017-07-11 11:04
141 查看
Python005条件分支语句
条件分支语句很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用
,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用。重要的事情说100遍。
#1.if-else
#(1)布尔值
if True:
print("111");
else:
print("222");
#111
if False:
print("111");
else:
print("222");
#222
#(2)整数值
if 0:
print("111");
else:
print("222");
#222
if 1:
print("111");
else:
print("222");
#111
if 2:
print("111");
else:
print("222");
#111
if -1:
print("111");
else:
print("222");
#111
if 1024:
print("111");
else:
print("222");
#111
#大概除了0之外,其余的都是被当作True来处理
#(3)浮点数
if 0.0:
print("111");
else:
print("222");
#222
if 2.12:
print("111");
else:
print("222");
#111
if -14.38:
print("111");
else:
print("222");
#111
#大概除了0.0之外,其余的都是被当作True来处理
#(4)其他类型
a=[];
if a:
print("111");
else:
print("222");
#222
a.insert(0, 1);
if a:
print("111");
else:
print("222");
#111
#列表,元组,字典,集合等大概都是如此
if None:
print("111");
else:
print("222");
#222
#2.if
a=True;
if a:
print("aaa");#aaa 执行了
a=False;
if a:
print("bbb");# 没有执行
#3.if-elif...-elif
#(90,100]优秀,(80,90]良好,[0,80]不及格.
score=85;
if score>90 and score<=100:
print("优秀");
elif score>80:
print("良好");
elif score>=0:
print("不及格");
#良好
score=80;
if score>90 and score<=100:
print("优秀");
elif score>80:
print("良好");
elif score>=0:
print("不及格");
#不及格
#4.if-elif...-elif-else
#(90,100]优秀,(80,90]良好,[0,80]不及格.
score = 250;
if score>90 and score<=100:
print("优秀");
elif score>80 and score<=90:
print("良好");
elif score>=0 and score<=80:
print("不及格");
else:
print("成绩吊炸天");
#成绩吊炸天
score = -250;
if score>90 and score<=100:
print("优秀");
elif score>80 and score<=90:
print("良好");
elif score>=0 and score<=80:
print("不及格");
else:
print("成绩吊炸天");
#成绩吊炸天
#5.条件语句嵌套
sex="男"
age=14;
if sex=="男":
if age>=14:
print('很有可能遗过精。');
else:
print('遗过精的可能性很小。');
elif sex=="女":
if age>=14:
print('很有可能来过大姨妈。');
else:
print('来过大姨妈的可能性很小。');
else:
print("这是一个神奇的性别,一定要好好珍惜。");
#很有可能遗过精。
条件分支语句很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用
,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用,很有用,很有用,很有用 ,很有用,很有用。重要的事情说100遍。
#1.if-else
#(1)布尔值
if True:
print("111");
else:
print("222");
#111
if False:
print("111");
else:
print("222");
#222
#(2)整数值
if 0:
print("111");
else:
print("222");
#222
if 1:
print("111");
else:
print("222");
#111
if 2:
print("111");
else:
print("222");
#111
if -1:
print("111");
else:
print("222");
#111
if 1024:
print("111");
else:
print("222");
#111
#大概除了0之外,其余的都是被当作True来处理
#(3)浮点数
if 0.0:
print("111");
else:
print("222");
#222
if 2.12:
print("111");
else:
print("222");
#111
if -14.38:
print("111");
else:
print("222");
#111
#大概除了0.0之外,其余的都是被当作True来处理
#(4)其他类型
a=[];
if a:
print("111");
else:
print("222");
#222
a.insert(0, 1);
if a:
print("111");
else:
print("222");
#111
#列表,元组,字典,集合等大概都是如此
if None:
print("111");
else:
print("222");
#222
#2.if
a=True;
if a:
print("aaa");#aaa 执行了
a=False;
if a:
print("bbb");# 没有执行
#3.if-elif...-elif
#(90,100]优秀,(80,90]良好,[0,80]不及格.
score=85;
if score>90 and score<=100:
print("优秀");
elif score>80:
print("良好");
elif score>=0:
print("不及格");
#良好
score=80;
if score>90 and score<=100:
print("优秀");
elif score>80:
print("良好");
elif score>=0:
print("不及格");
#不及格
#4.if-elif...-elif-else
#(90,100]优秀,(80,90]良好,[0,80]不及格.
score = 250;
if score>90 and score<=100:
print("优秀");
elif score>80 and score<=90:
print("良好");
elif score>=0 and score<=80:
print("不及格");
else:
print("成绩吊炸天");
#成绩吊炸天
score = -250;
if score>90 and score<=100:
print("优秀");
elif score>80 and score<=90:
print("良好");
elif score>=0 and score<=80:
print("不及格");
else:
print("成绩吊炸天");
#成绩吊炸天
#5.条件语句嵌套
sex="男"
age=14;
if sex=="男":
if age>=14:
print('很有可能遗过精。');
else:
print('遗过精的可能性很小。');
elif sex=="女":
if age>=14:
print('很有可能来过大姨妈。');
else:
print('来过大姨妈的可能性很小。');
else:
print("这是一个神奇的性别,一定要好好珍惜。");
#很有可能遗过精。
相关文章推荐
- python的条件分支语句(if)
- Python中的条件分支语句,if , else , else if
- Python学习入门基础教程(learning Python)--3.3 分支语句的条件表达式详解 .
- python中的条件语句,分支语句以及逻辑运算符和比较运算符
- Python 【条件分支】(if 语句) 学习笔记
- 《Python 第五章》条件,循环和其他语句
- [Python 05] 条件,循环和其他语句
- 【转】软件测试中条件覆盖,路径覆盖,语句覆盖,分支覆盖的区别
- python学习笔记-第2章节 分支,循环,还有条件
- beginning python summary chapter 5 - 条件,循环和其他语句
- 使用控制结构——条件分支语句——二重条件条件
- Python基础教程学习笔记----第五章 条件、循环和其他语句
- 软件测试中条件覆盖,路径覆盖,语句覆盖,分支覆盖的区别
- 使用控制结构——条件分支语句——CASE语句
- Python中条件选择和循环语句使用方法介绍
- 《重构--改善既有代码的设计》读书笔记之四:将条件分支语句放入合适类中
- python 条件,循环和其他语句的学习笔记
- Python中的条件语句
- 软件测试中条件覆盖,路径覆盖,语句覆盖,分支覆盖的区别
- vb.net条件分支语句