Computer Science Related Others Courses AvailableThe Best Codder.blogspot.com
Posts

Logical and Bitwise Not Operators on Boolean

 

Logical and Bitwise Not Operators on Boolean

# A Python program that uses Logical Not or ! on boolean
a = not True
b = not False
print a
print b
# Output: False
#         True
Output
0
1
1
0

The outputs of above programs are as expected, but the outputs following programs may not be as expected if we have not used Bitwise Not (or ~) operator before.
 

# A Python program that uses Bitwise Not or ~ on boolean
a = True
b = False
print ~a
print ~b

Post a Comment

© Python . The Best Codder All rights reserved. Distributed by