zoukankan      html  css  js  c++  java
  • 流程控制——if判断

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

    sex='female'
    age=18
    is_beautiful=True
    
    if sex == 'female' and age > 16 and age < 20 and is_beautiful:
        print('开始表白。。。')
    
    print('other code1...')
    print('other code2...')
    print('other code3...')
    

    语法二:
    if 条件:
      # 条件成立时执行的子代码块
      代码1
      代码2
      代码3
      else:
      # 条件不成立时执行的子代码块
      代码1
      代码2
      代码3

    sex='female'
    age=38
    is_beautiful=True
    
    if sex == 'female' and age > 16 and age < 20 and is_beautiful:
        print('开始表白。。。')
    else:
        print('阿姨好。。。')
    
    
    print('other code1...')
    print('other code2...')
    print('other code3...')
    

     

    语法三:
    if 条件1:
      if 条件2:
        代码1
        代码2
        代码3

     

    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('在一起。。。')
        else:
            print('什么爱情不爱情的,爱nmlgb的爱情,爱nmlg啊.')
    else:
        print('阿姨好。。。')
    
    
    print('other code1...')
    print('other code2...')
    print('other code3...')
    

     

    语法四:
    if 条件1:
      代码1
      代码2
      代码3
    elif 条件2:
      代码1
      代码2
      代码3
    elif 条件3:
      代码1
      代码2
      代码3
    .......
    else:
      代码1
      代码2
      代码3

     

  • 相关阅读:
    CentOS 7 配置hadoop(五) 配置sqoop(伪分布)
    CentOS 7 配置hadoop(四) 配置hive(伪分布)
    CentOS 7 配置hadoop(三) 配置hbase(伪分布)
    java高级之NIO
    字符编码与序列化
    java高级之IO流 -2
    java中的值传递和引用传递
    事务相关知识点
    mybatis中批量更新sql语句,trim、foreach标签,varchar定义理解
    java IO流之File类的使用
  • 原文地址:https://www.cnblogs.com/king-home/p/10574471.html
Copyright © 2011-2022 走看看