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 | Accessing Key-value in Dictionary
- Python | Accessing index and value in list
- Python | Accessing nth element from tuples in list
- Python | Accessing all elements at given list of indexes
- Class & Instance Attributes in Python
- Filtering Images based on size attributes in Python
- Counters in Python | Set 2 (Accessing Counters)
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- List methods in Python
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Python | Float type and its methods
- Dunder or magic methods in Python
- Python Input Methods for Competitive Programming
- Python | Implementing 3D Vectors using dunder methods
- Analysis of Different Methods to find Prime Number 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.