zoukankan      html  css  js  c++  java
  • Python 逻辑运算符,not in,in

    一、逻辑运算符

    and     or   not       

    优先级 () > not > and > or

    1 print(4 > 3 or 4 < 3 and 1!=1)
    2 print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
    3 print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)
    4 print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
    5 print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
    and or not
    1 print(4 or 3)
    2 print(2 or 3)
    3 print(1 or 3)
    4 print(0 or 3)
    5 print(-1 or 3)
    print(x or y), 如果 x 为真,则值为x,否则为y
    print(x or y),
    如果 x 为真,则值为y,否则为x
    1 print(4 and 3)
    2 print(2 and 3)
    3 print(1 and 3)
    4 print(0 and 3)
    5 print(-1 and 3)
    
    
    print(x and y) 和 or 相反
    1 print( 2>3 or 3)
    2 print( 2>2 or 0)
    3 print( 2>3 or 3)

    3 > 2  打印 True

     

    二、bool 与 int 转换

      bool 转换成 int 只有 0 和1

      int 转换成 bool ,0为False,其他所有为True

    三、in         not  in

    1 str = 'abcdefghijklmn'
    2 print('a' in str)
    3 print('bcde' in str)
    4 print('bm' in str)
    1 comment = input('Please enter comment:')
    2 if '台独' in comment:
    3     print('Your comments contain illegal characters!')
    4 elseprint('Comments increasing success')
  • 相关阅读:
    check_mysql.sh
    shell 数组长度
    Shell脚本中计算字符串长度的5种方法
    非缓冲文件编程(实时操作)
    ferror,clearerr和EOF含义
    密码库生成
    筛选出多个数据并判断
    扫描有分隔符的数据
    unicode文件处理(如果是ANSI编码就不需要了)
    ferror,perror,cleaner
  • 原文地址:https://www.cnblogs.com/zhzhlong/p/7701134.html
Copyright © 2011-2022 走看看