Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created September 24, 2019 20:36
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 adamloving/714438d7ed1eff231ba2b5e0c6ed2569 to your computer and use it in GitHub Desktop.
Save adamloving/714438d7ed1eff231ba2b5e0c6ed2569 to your computer and use it in GitHub Desktop.
Python truth table and truthiness
import math
values = [
True, False, 1, 0, -1, "true", "false", "1", "0", "-1", "", None, math.inf, -math.inf, [], {}, [[]], [0], [1]
]
print("Truth Table")
print("-----------")
for value in values:
print(f"\t", end="")
print(value, end="")
print("")
for value in values:
print(value, end="\t")
for value2 in values:
print(value == value2, end="\t")
print("")
print("\n\nTruthiness")
print("----------")
for value in values:
truthy = True if value else False
print(f"{value}\t{truthy}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment