Skip to content

Instantly share code, notes, and snippets.

@medina
Created September 22, 2016 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save medina/2dcb3a53edfb5f69947f44693ceeb771 to your computer and use it in GitHub Desktop.
Save medina/2dcb3a53edfb5f69947f44693ceeb771 to your computer and use it in GitHub Desktop.
Boolean Logic w/ Python
import operator
print "\t".join([ "A", "B", "A and B", "A or B", "A xor B"])
for a in [True, False]:
for b in [True, False]:
print "\t".join(
str(x) for x in [
a, b, operator.iand(a,b), operator.ior(a,b), operator.ixor(a,b),
])
# A B A and B A or B A xor B
# True True True True False
# True False False True True
# False True False True True
# False False False False False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment