3.python3 数据运算

发布时间:2019-09-24 08:26:54编辑:auto阅读(2052)

    一、数据运算 

    算数运算:

    比较运算:

    赋值运算:

    逻辑运算:

    成员运算:

    身份运算:

    位运算:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    #!/usr/bin/python
      
    = 60            # 60 = 0011 1100
    = 13            # 13 = 0000 1101
    = 0
      
    = a & b;        # 12 = 0000 1100
    print "Line 1 - Value of c is ", c
      
    = a | b;        # 61 = 0011 1101
    print "Line 2 - Value of c is ", c
      
    = a ^ b;        # 49 = 0011 0001 #相同为0,不同为1
    print "Line 3 - Value of c is ", c
      
    = ~a;           # -61 = 1100 0011
    print "Line 4 - Value of c is ", c
      
    = a << 2;       # 240 = 1111 0000
    print "Line 5 - Value of c is ", c
      
    = a >> 2;       # 15 = 0000 1111
    print "Line 6 - Value of c is ", c

    *按位取反运算规则(按位取反再加1)   详解http://blog.csdn.net/wenxinwukui234/article/details/42119265

     

    运算符优先级:

    更多内容:猛击这里


关键字