Created
August 29, 2022 08:31
-
-
Save matthiasgoergens/6defaa0754fa4ffbee8770ae2de92a0e to your computer and use it in GitHub Desktop.
Booleans in Python
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
class A: | |
def __init__(self, x): | |
self.x = x | |
def __bool__(self): | |
print(f'bool: {self}') | |
return False | |
def __str__(self): | |
return f'A(x={self.x})' | |
print("Variant 1") | |
a = A(1) and A(2) | |
if a: | |
print("True") | |
print("Variant 2") | |
if A(3) and A(4): | |
print("True") |
Author
matthiasgoergens
commented
Aug 29, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment