Last active
August 19, 2025 06:35
-
-
Save GeroZayas/1c9007f38e8f0aff2dd42179eb239438 to your computer and use it in GitHub Desktop.
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
| # Stupid simple idea but very useful | |
| # if some condition is met, then we return new value, or charged old value | |
| # Else, we return the (unchanged) original value | |
| def change_if_new(new_thing, old_thing): | |
| if new_thing: | |
| return new_thing | |
| # else | |
| return old_thing | |
| name = "Gero" | |
| print(name) # Gero | |
| name = change_if_new(new_thing="Enrique", old_thing=name) | |
| print(name) # Enrique | |
| name = change_if_new(new_thing=None, old_thing=name) # No change | |
| name = change_if_new(new_thing=0, old_thing=name) # No change | |
| name = change_if_new(new_thing=False, old_thing=name) # No change | |
| print(name) # Enrique |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment