Dynamic attributes in Python are terminologies for attributes that are defined at runtime, after creating the objects or instances. In Python we call all functions, methods also as an object. So you can define a dynamic instance attribute for nearly anything in Python. Consider the below example for better understanding about the topic.
Now, the above program seems to be confusing, but let’s try to understand it. Firstly let’s see the objects, g and value(functions are also considered as objects in Python) are the two objects. Here the dynamic attribute for both the objects is “d1”. This is defined at runtime and not at compile time like static attributes.
Note: The class “GFG” and all other objects or instances of this class do not know the attribute “d1”. It is only defined for the instance “g”.
False True Nikhil
Traceback (most recent call last): File "/home/fbcfcf668619b24bb8ace68e3c400bc6.py", line 19, in
print(e1.name) AttributeError: 'GFG' object has no attribute 'name'
- Python | PIL Attributes
- Accessing Attributes and Methods in Python
- Class and Instance Attributes in Python
- How to Get a List of Class Attributes in Python?
- Python PIL Attributes | Image.width Method
- Python PIL Attributes | Image.height method
- Filtering Images based on size attributes in Python
- Implementation of Dynamic Array in Python
- Python | Implementing Dynamic programming using Dictionary
- Monkey Patching in Python (Dynamic Behavior)
- wxPython - Get Default Attributes of StaticText
- wxPython | Get default attributes of Radio Box
- wxPython - Get visual attributes of static box
- Type Systems:Dynamic Typing, Static Typing & Duck Typing
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python - Read blob object in python using wand library
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
- Python | Index of Non-Zero elements in Python list
- MySQL-Connector-Python module in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.