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

    一 .数学运算符

    表答式: 有变量 常量和运算符组成的式子

     算术运算符和算术运算表达式 

      以下假设变量:a=10,b=20

     算术运算符
       + - * / % ** //

     加 减 乘 除 取模 幂 取整

     以下假设变量:a=10,b=20

     1. 算术表达式:

    num1=5
    num2=3
    print(num1+num2)  # 8
    print(num1-num2)  # 2
    print(num1*num2)  # 15
    print(num1/num2)  #1.6666666667
    print(num1%num2)  # 2
    print(num1**num2) #125
    print(num1//num2) #1

    赋值运算符  =变量=表达式

    2. 符合运算符

     以下假设变量:a=10,b=20

     +=   a+=b    a=a+b
      *=   a*=b    a=a*b
      /=   a/=b    a=A/b
      %=   a%=b    a=a%b
      **=  a**=b   a=a**b
      //=  a//=b   a=a//b

    二 . 逻辑运算符

    == != > < >= <=
    关系表达式
    1+2>3+4
    格式 : 表达式 关系运算符 表达式2

    #三者的优先级从高到低分别是:not,or,and
    >>> 3>4 and 4>3 or 1==3 and 'x' == 'x' or 3 >3
    False
    #最好使用括号来区别优先级,其实意义与上面的一样
    >>> (3>4 and 4>3) or ((1==3 and 'x' == 'x') or 3 >3)
    False 

    逻辑运算符

    1.逻辑与 and
         逻辑与运算符表达式 表达式1 and 表达式2
         有一个为假就为假 其他为真

    2. 逻辑或 or
        逻辑或运算符表达式 表达式1 or 表达式2
        假假为假 其他为真 (有一个为真都为真)

    3. 短路原则and

        表达式1 and 表达式2 and 表达式3 and 表达式4.....and 表达式n

    4. 成员运算符

        in 如果在指定的序列中找到了值返回true 否则返回fales
        not in 意思在指定的序列中没有找到值返回true 否则返回fales

    5. 身份运算符

       is : 判断两个标识符是不是引用同一个对象
       is not :判断两个标识符是不是引用不同的对象

    7. 运算符优先级

       **

       ~ + - (一元加减)

       */ % //

       + -

       >> <<
      &

      <= < > >=

      == !=

      = %= += //=

      is is not

      in not in

    #能被4整除 但是不能被100整除  或者  能被400整除
    year=int(input("请你输入一个数字:"))
    
    if year%400==0 or(year%4==0 and year%100!=0):
    
       print("是闰年")
    else:
       print("不是闰年")
  • 相关阅读:
    Android ClearEditText:输入用户名、密码错误时整体删除及输入为空时候晃动提示
    Activity界面切换动画特效。
    点击事件的确认取消对话框。
    安卓菜单的实现,各种添加菜单的方法。
    联系人的侧边字母索引ListView 将手机通讯录姓名通过首字母排序。
    获取手机屏幕密度。
    Android统计图表MPAndroidChart.
    性能测试
    自动化框架
    排序算法
  • 原文地址:https://www.cnblogs.com/Sup-to/p/10828947.html
Copyright © 2011-2022 走看看