Last active
December 2, 2019 16:17
-
-
Save geoffreygarrett/d163a0eefe3ac033b124f359bb17cabb to your computer and use it in GitHub Desktop.
Conditionally created default arguments in Python class instantiation using "or".
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 Test: | |
def __init__(self, arg=None): | |
self.test_arg = arg or "Default arg" | |
test1 = Test() | |
test2 = Test("Not Default arg") | |
print(test1.test_arg) | |
# Default arg | |
print(test2.test_arg) | |
# Not Default arg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case in
poliastro
:https://github.com/poliastro/poliastro/blob/89768818f0387ca77eaa78054a3aabbb8cdb20ff/src/poliastro/plotting/_base.py#L25