Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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