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
- Python | PIL Attributes
- Dynamic Attributes in Python
- How to Get a List of Class Attributes in Python?
- Class and Instance Attributes in Python
- Python PIL Attributes | Image.width Method
- Python PIL Attributes | Image.height method
- Python | Accessing Key-value in Dictionary
- Filtering Images based on size attributes in Python
- Python | Accessing index and value in list
- Python | Accessing variable value from code scope
- Python | Accessing all elements at given list of indexes
- Python | Accessing nth element from tuples in list
- Accessing Data Along Multiple Dimensions Arrays in Python Numpy
- List methods in Python
- Private Methods in Python
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- Bound methods python
- Methods of Ordered Dictionary in Python
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Dunder or magic methods 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 firstname.lastname@example.org. 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.