Attributes of a class are function objects that define corresponding methods of its instances. They are used to implement access controls of the classes.
Attributes of a class can also be accessed using the following built-in methods and functions :
- getattr() – This function is used to access the attribute of object.
- hasattr() – This function is used to check if an attribute exist or not.
- setattr() – This function is used to set an attribute. If the attribute does not exist, then it would be created.
- delattr() – This function is used to delete an attribute. If you are accessing the attribute after deleting it raises error “class has no attribute”.
The following methods are explained with the example given below :
Harsh True 152
Static methods : A static method is a method[member function] that don’t use argument self at all. To declare a static method, proceed it with the statement “@staticmethod”.
4 9 9
Accessing attributes and methods of one class in another class
Accessing attributes and methods of one class in another class is done by passing the object of one class to another.
Explained with the example given below :
3 3 2
- Class and Instance Attributes in Python
- Difference between attributes and properties in Python
- Filtering Images based on size attributes in Python
- Python | PIL Attributes
- Python PIL Attributes | Image.width Method
- Python PIL Attributes | Image.height method
- How to Get a List of Class Attributes in Python?
- Dynamic Attributes in Python
- Python | Accessing index and value in list
- attributes in C++
- Tags vs Elements vs Attributes in HTML
- wxPython - Get Default Attributes of StaticText
- wxPython | Get default attributes of Radio Box
- wxPython - Get visual attributes of static box
- Counters in Python | Set 2 (Accessing Counters)
- Python | Accessing Key-value in Dictionary
- Python | Accessing all elements at given list of indexes
- Python | Accessing nth element from tuples in list
- Python | Accessing variable value from code scope
- Accessing Data Along Multiple Dimensions Arrays in Python Numpy
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.