Skip to content

Instantly share code, notes, and snippets.

@mentix02
Created August 15, 2025 21:19
Show Gist options
  • Select an option

  • Save mentix02/d57258d2306a7da53146d853029c4993 to your computer and use it in GitHub Desktop.

Select an option

Save mentix02/d57258d2306a7da53146d853029c4993 to your computer and use it in GitHub Desktop.
Visualise short cuiting in action in Python
class Klass:
@property
def value_a(self) -> bool:
print('Value a accessed')
return False
@property
def value_b(self) -> bool:
print('Value b accessed')
return False
@property
def value_c(self) -> bool:
print('Value c accessed')
return False
@property
def value_d(self) -> bool:
print('Value d accessed')
return True
LINE_SIZE = 35
print('''a = False
b = False
c = False
d = True''')
obj = Klass()
print('=' * LINE_SIZE)
res = not (obj.value_a or obj.value_b)
print('if not (a or b):', res)
print('=' * LINE_SIZE)
res = obj.value_d and obj.value_c and obj.value_b
print('if d and c and b:', res)
print('=' * LINE_SIZE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment