[2.17] Python study notes shift operators, Logical Operators

Shift operator

Left-shift operator

\ (<< \) , the end of the binary number corresponding to a zero-fill, high natural overflow (Fled to nothingness

print( 5 << 2 )

The \ (5 \) binary number shifted left two
that is \ (101 \) becomes \ (10100 \)

Right-shift operator

\ (>> \) , a binary number corresponding to the right, end the number of natural overflow (* 2 ~ ~ ~ ~ escape into nothingness

print( 7 >> 1 )

The \ (111 \) becomes \ (11 \)

Logical Operators

Logic and

\ (Python \) in the logic and weird, is an English word \ (and \)

if 表达式1 and 表达式2 :
    print( 1 )

All the expression is true, the return value is true, the output 1

Note : An expression can not have an assignment, otherwise it will error

Logical or

if 表达式1 or 表达式2 :
    print( 1 )

As long as the expression \ (2 \) has a true, true is returned, an output

Logical NOT

if not 表达式 :
    print( 1 )

If the expression is true, the whole is false, not output
if the expression is false, the whole truth, output 1

Guess you like

Origin www.cnblogs.com/with6676/p/12324563.html