您的位置:首页 > 编程语言 > Python开发

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("这是一个神奇的性别,一定要好好珍惜。");

#很有可能遗过精。 

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: