Python documentation for shifting operations and binary bitwise operations says that arguments must be integers, but the below expressions evaluates without error, however giving odd results for <<
and >>
.
Is there an additional place I should look for documentation of &
etc. when using boolean arguments, or is there some good explanation for evaluation and results ?
- True & False: False (class 'bool')
- True | False: True (class 'bool')
- True ^ False: True (class 'bool')
- ~ True: -2 (class 'int')
- ~ False: -1 (class 'int')
- True << True: 2 (class 'int')
- False >> False: 0 (class 'int')
Code:
# Python ver. 3.3.2
def tryout(s):
print(s + ':', eval(s), type(eval(s)))
tryout('True & False')
tryout('True | False')
tryout('True ^ False')
tryout('~ True')
tryout('~ False')
tryout('True << True')
tryout('False >> False')