Created
September 24, 2019 20:36
-
-
Save adamloving/714438d7ed1eff231ba2b5e0c6ed2569 to your computer and use it in GitHub Desktop.
Python truth table and truthiness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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