if语法

语法一:
  if 条件:   条件成立时执行的子代码块

   

age_of_girl=31
if age_of_girl > 30:
    print('阿姨好')

语法二:if + else  
  if 条件:  条件成立时执行的子代码块

    代码....

  else:      条件不成立时执行的子代码块

    代码...

age_of_girl=18
if age_of_girl > 30:
    print('阿姨好')
else:
    print('小姐好')

语法三:if + if

  if 条件1:

    if 条件2:

      代码xxx

sex='female'
age=18
is_beautiful=True
is_successful=True
height=1.70
if sex == 'female' and age > 16 and age < 20 and is_beautiful 
        and height > 1.60 and height < 1.80: 
    print('开始表白。。。')
    if is_successful:
        print('在一起。。。')

语法四:if + elif +elif +else

    if 条件:

      代码。。。。
    elif 条件:
      代码....
    elif 条件:
      代码。。。
    else 条件:
      代码,,,

score=input('>>: ')
score=int(score)

if score >= 90:
    print('优秀')
elif score >= 80:
    print('良好')
elif score >= 70:
    print('普通')
else:
    print('很差')
原文地址:https://www.cnblogs.com/lakei/p/10574108.html