python入门学习笔记(四)——if语句

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40301026/article/details/80017830

5. if语句

5.1  简单if语句

sum = 20;

if sum < 19:

    print('OK')

    

 

5.2  if-else语句

name = ['sss','dddd','eeee']

if name == 'cccc':

    print('OK')

else:

    print('NO')

##########################

NO

5.3 if-elif-elif(多条件)

age = 12

if age < 4 :

    print('年龄小于四岁。')

elif age < 10 :

    print('年龄大于等于四岁,小于十岁。')

elif age > 10 :

    print('年龄大于十岁。')

5.4 if-elif-elif-else(多条件)

age = 12

if age < 4:

    print('年龄小于四岁')

elif age <10:

    print('年龄小于十岁大于等于四岁')

else:

    print('年龄大于等于十岁')

5.5 andor 类似逻辑运算符 &&||

age = 12

if age < 4 and age < 8:

    print('pa = 0')

 

else:

    print('pa = 1')

######################

pa = 1

 


猜你喜欢

转载自blog.csdn.net/qq_40301026/article/details/80017830
今日推荐