Created
August 15, 2025 21:19
-
-
Save mentix02/d57258d2306a7da53146d853029c4993 to your computer and use it in GitHub Desktop.
Visualise short cuiting in action in Python
This file contains hidden or 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 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