zoukankan      html  css  js  c++  java
  • python里面的数学

    一.基本运算符

    1.算数运算

    2.比较运算

    特殊情况:!= 不等于 新版本不支持 <> 不等号

    3.赋值运算

    4.逻辑运算

    not : 非   非真即假,非假即真.   -

    and : 并且    左右两端同时为真,结果才为真.   *

    or : 或者      左右两端有一个为真,结果就是真.   +

    True : 真    1    判断的结果

    False : 假   0     判断的结果

    print(3 > 4 or 4 < 3 and 1 == 1)  # False
    print(1 < 2 and 3 < 4 or 1 > 2)  # True
    print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # True
    print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # False
    print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False
    print((not 2 > 1 and 3 < 4) or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False

    当出现  x or y 时 , 判断x是否为0 ; 如果x==0 ,则返回y ,否则返回x.(x and y 恰恰相反)

    5.成员运算

    in : 包含     字符串  in  字符串   

         字符串 in 列表  等等

    content = input("请输入你的评论:")
    if "马冬梅" in content :   #判断content里面有没有马冬梅
        print("你的评论不合法!")
    else:
        print("你的评论的是合法的!")
    
    ad = input("请输入你的广告词:")
    if "最" in ad or "第一" in ad or "全球" in ad :  # or 满足任何一个都不合法
        print("你的广告词不合法!")
    else:
        print("你的广告词合法!")
  • 相关阅读:
    Python之运算符
    Day1_Python基础_10..pyc是个什么鬼?
    Day1_Python基础_9.模块初识
    Day1_Python基础_8.用户输入
    Day1_Python基础_7.字符编码
    Day1_Python基础_6.变量/字符编码
    Day1_Python基础_5.Hello World 程序
    Day1_Python基础_4.Python安装
    Day1_Python基础_3.Python2 or 3 ?
    Day1_Python基础_2.Python历史
  • 原文地址:https://www.cnblogs.com/q767498226/p/10028439.html
Copyright © 2011-2022 走看看