zoukankan      html  css  js  c++  java
  • 身份运算符/流程控制if

    身份运算符

    in

    • 判断一个字符或者字符串是否存在于一个大字符串/元素中/key列表中

    print("e" in "hello eogn")
    
    True
    
    print('z' in ['c','y','z'])
    
    True

    print('k1' in {'k1':666,'k2':01})
    print(01 in {'k1':666,'k2':01})

    True
    False

      

    not in

    判断一个字符或者字符串是否存在于一个大字符串中/元素/key

    print("e" not in "hello eogn")
    
    False
    
    
    
    print('z' not in ['c','y','z'])
    
    False

    print('k1' in {'k1':666,'k2':01})
    print(01 in {'k1':666,'k2':01})

    False
    True

      

    身份运算符  is / not is

    • is:引用的是同一个对象则返回 True,否则返回 False
    • not is:判断两个标识符是不是引用自不同对象,如果引用的不是同一个对象则返回结果 True,否则返回 False
    x = 1
    y = 1
    print(x is y)
    
    True
    

      

    x = 1
    y = 1
    print(x is not y)
    
    False
    

      

        if  的语法。

    if的缩进

    if条件:

         代码1

         if条件2:

      

    if方法一:

        代码1

        代码2

        代码3

      

    age = 60
    is_beautiful = True
    star = '水瓶座'
    
    if age > 16 and age < 20 and is_beautiful and star == '水瓶座':
        print('我喜欢你,我们在一起吧!')
    

      

    方法二:

    if 条件:
         代码1
      else:
         代码1

      

    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
      else 条件3:
        代码1

    score = input('请输入您的成绩:')
    score = int(score)
    
    if score >= 90:
        print('优秀啊,小伙子!')
    elif score >= 80:
        print('还可以吧!')
    elif score >= 70:
        print('要努力了呀,小伙子')
    elif score >= 60:
        print('准备叫家长吧!')
    else:
        print("滚啊!!!"
    

      

  • 相关阅读:
    Centos 7 开放查看端口 防火墙关闭打开
    idea将项目导出为war包
    webstorm 注册服务器
    centos 6.4系统双网卡绑定配置详解
    centos所有版本镜像下载地址
    浅谈Nginx负载均衡与F5的区别
    勒索病毒应急响应计划
    Python网络编程常用代码
    Flask debug 模式 PIN 码生成机制安全性研究笔记
    Pythonic定义
  • 原文地址:https://www.cnblogs.com/Tornadoes-Destroy-Parking-Lots/p/12433524.html
Copyright © 2011-2022 走看看