zoukankan      html  css  js  c++  java
  • 4.运算符

    运算符

    一、算数运算

    a=10 b=20

    image-20190622181704484

    二、比较运算

    a=10 b=20

    image-20190622181732841

    三、赋值运算

    a =10 b=20

    image-20190622181750923

    四、逻辑运算

    image-20190622181808641

    • and 真真=True,否则为False

    • or 有一个为真则=Ture

    • not 取相反

    • ()优先运算

    • 同级运算从左到右

    逻辑运算口诀:比大小等不等,并且或者分先后,带括号的优第一,同级运算左往右

    • 实例

      # print(0 or 4 and 3 or 7 or 9 and 6)         #0为False   非0的都为True
      print("------------------")                   #运算and,运算时有0则取值为0(有一个为False时,结果就为False)
                                                    #当两个值都为真时,把后者(起决定结果的值)作为输出值
      print(4 and 0)                                #输出为0
      print(9 and 6)                                #输出为6
      print(6 and 9)                                #输出为9
      
      print("------------------")                   #运算or,运算时会把第一个真值(决定结果的值)作为输出值
                                                    #当两个值都为伪时,结果输出为0
      print(0 or 0)                                 #输出为0
      print(0 or 3)                                 #输出为3
      print(3 or 7)                                 #输出为3
      print(7 or 3)                                 #输出为7
      
      print("------------------")                   #运算not,取相反的逻辑结果输出
                                                    #not(真)则为伪;not(伪)则为真
      print(not(0 or 0))                            #输出True
      print(not(0 or 3))                            #输出False
      print(not(1 and 2))                           #输出False
      print(not(0 and 3))                           #输出True
      

    五、成员运算

    in not in :

    判断子元素是否在原字符串(字典,列表,集合)中:

    例如:

    #print('喜欢' in 'dkfljadklf喜欢hfjdkas')            #输出True
    #print('a' in 'bcvd')                               #输出False
    #print('y' not in 'ofkjdslaf')                      #输出True
    
  • 相关阅读:
    adb使用项目导入等
    ThreadLocal类理解
    Spring MVC MyBatis
    Spring MVC原理图
    Spring MVC返回JSON的几种方法
    Understanding REST
    链表
    存储构造题(Print Check)
    线状DP(石子归并)
    线段树(与区间有关的操作)
  • 原文地址:https://www.cnblogs.com/yangte/p/13371239.html
Copyright © 2011-2022 走看看