zoukankan      html  css  js  c++  java
  • Python -- 逻辑运算符 -- and -- if语句

    import keyword
    print(keyword.kwlist)


    # ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break',
    # 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally',
    # 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal',
    # 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

    # a = 5
    # b = 10
    # c = 6
    # print(a != b)
    # print(a<b and b<c)

    # print(1>2 and 3 < 4 or 4>5 and 2 > 1 or 9< 8)

    # 优先级 () not and or
    # x or y x为真就是x 否y
    # x and y x为真就是y 否x
    # not x x为真就是false 否 true

    # in 在什么什么里面
    # not in 不在什么什么里面
    print('ni' not in 'nihaoma')

    # 三元运算符
    # 结果1 if 条件 else 结果2 true就是 if左边的 否 右边
    re = 55 if 3 > 2 else 66
    print(re)

    print('if' in keyword.kwlist)





    ---------------------------------------------------------------------------------------------


     

    import keyword
    # print('if' in keyword.kwlist) #查看if是否是关键字
    # if 表达式 :

    # if 5<3 :
    # print('张飞')
    # print('李艳')

    # if 条件:
    # pass
    # else:
    # pass

    # a,b=5,3
    # if a>b :
    # print(a)
    # else:
    # print(b)

    # 嵌套if

    a,b,c = 5,3,2

    # if a>b:
    # if a>c:
    # print(a)
    # else:
    # print(c)
    # else:
    # if b>c:
    # print(b)
    # else:
    # print(c)

    # 多重判断
    # score = 99;
    # if score >= 0 and score <= 60:
    # print('及格')
    # elif score >= 61 and score <= 80:
    # print('良好')
    # elif score >=81 and score <=100:
    # print('优秀')

    if len('1') > 3:
    print('长')

    if 'nihao'.startswith('ni'): #以什么开头startswith
    print(True)

    if (i := 5) < 3:
    print(i)

    if (n := len(a)) > 3 :
    print('你好')

  • 相关阅读:
    面向对象之prototype,__proto__
    Screen对象
    location对象
    history对象
    JS计时器
    window对象
    Dom操作html详细
    终端 git log 修改样式
    null 和 NULL 判断
    textfield设置左边距
  • 原文地址:https://www.cnblogs.com/Rice-Ayba/p/13267451.html
Copyright © 2011-2022 走看看