• 条件与判断


    判断前提:条件

    # 第一大类:显式布尔值
    # 1.1 条件可以是:比较运算符
    # age = 18
    # print(age > 16)  # 条件判断之后会得到一个布尔值
    
    # 1.2 条件可以是:True、False
    # is_beautiful=True
    # print(is_beautiful)
    
    
    # 第二大类:隐式布尔值,所有的值都可以当成条件去用
    # 其中0、None、空(空字符串、空列表、空字典)=》代表的布尔值为False,其余都为真
    

    一、if判断

    语法1:
    if 条件:
        代码1
        代码2
        代码3
    # age = 60
    # is_beautiful = True
    # star = '水平座'
    #
    # if age > 16 and age < 20 and is_beautiful and star == '水平座':
    #     print('我喜欢,我们在一起吧。。。')
    ## print('其他代码.............')
    
    语法2:
    if 条件:
        代码1
        代码2
        代码3
    else:
        代码1
        代码2
        代码3
    # age = 60
    # is_beautiful = True
    # star = '水平座'
    #
    # if age > 16 and age < 20 and is_beautiful and star == '水平座':
    #     print('我喜欢,我们在一起吧。。。')
    # else:
    #     print('阿姨好,我逗你玩呢,深藏功与名')
    # print('其他代码.............')
    
    
    语法3:
    if 条件1:
        代码1
        代码2
        代码3
    elif 条件2:
        代码1
        代码2
        代码3
    elif 条件2:
        代码1
        代码2
        代码3
    # score=73
    # if score >= 90:
    #     print('优秀')
    # elif score >= 80 and score < 90:
    #     print('良好')
    # elif score >= 70 and score < 80:
    #     print('普通')
    
    # 改进
    # score = input('请输入您的成绩:') # score="18"
    # score=int(score)
    #
    # if score >= 90:
    #     print('优秀')
    # elif score >= 80:
    #     print('良好')
    # elif score >= 70:
    #     print('普通')
    
    语法3:
    if 条件1:
        代码1
        代码2
        代码3
    elif 条件2:
        代码1
        代码2
        代码3
    elif 条件2:
        代码1
        代码2
        代码3
    ...
    else:
        代码1
        代码2
        代码3
        
    # score = input('请输入您的成绩:') # score="18"
    # score=int(score)
    # if score >= 90:
    #     print('优秀')
    # elif score >= 80:
    #     print('良好')
    # elif score >= 70:
    #     print('普通')
    # else:
    #     print('很差,小垃圾')
    # print('=====>')
    
    if嵌套if
    age = 17
    is_beautiful = True
    star = '水平座'
    
    if 16 < age < 20 and is_beautiful and star == '水平座':
        print('开始表白。。。。。')
        is_successful = True
        if is_successful:
            print('两个从此过上没羞没臊的生活。。。')
    else:
        print('阿姨好,我逗你玩呢,深藏功与名')
    
    print('其他代码.............')
    
    
  • 相关阅读:
    线程池优化之充分利用线程池资源
    Spring异步调用原理及SpringAop拦截器链原理
    使用pdfBox实现pdf转图片,解决中文方块乱码等问题
    Spring BPP中优雅的创建动态代理Bean
    转载:ThreadPoolExecutor 源码阅读
    Springboot定时任务原理及如何动态创建定时任务
    SpringSecurity整合JWT
    SpringMvc接口中转设计(策略+模板方法)
    HashMap 源码阅读
    支付宝敏感信息解密
  • 原文地址:https://www.cnblogs.com/chenyoupan/p/12430221.html
Copyright © 2020-2023  润新知