一个属性表示多个状态

if __name__ == '__main__':

    first  = 1
    second = 1 << 2
    three  = 1 << 4
    four   = 1 << 6

    mark = 0
    mark |= first
    #mark |= second
    mark |= three
    #mark |= four

    if mark&first == first:
        print("fisrt:%s,%s" ,(mark&first) ,mark)

    if mark&second == second:
        print("second:%s,%s",(mark&second) ,mark)

    if mark&three == three:
        print("three:%,%ss", (mark&three) ,mark)

    if mark & four == four:
        print("four:", (mark & three), mark)

猜你喜欢

转载自blog.csdn.net/epeaktop/article/details/78982397