Created
May 23, 2023 07:18
-
-
Save bbelderbos/d76c9143675bf38ba89ce2a62dd2e5a1 to your computer and use it in GitHub Desktop.
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 Dog: | |
... def __init__(self, breed, color): | |
... self.breed = breed | |
... self.color = color | |
... | |
>>> dog1 = Dog("bulldog", "brown") | |
>>> | |
>>> dog1 | |
<__main__.Dog object at 0x7fe114d36580> | |
>>> dog1.attr | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: 'Dog' object has no attribute 'attr' | |
>>> getattr(dog1, "breed") | |
'bulldog' | |
>>> getattr(dog1, "attr") | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: 'Dog' object has no attribute 'attr' | |
>>> getattr(dog1, "attr", "default_value") | |
'default_value' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment