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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Class and Instance Attributes in Python
- Difference between attributes and properties in Python
- Python | Accessing index and value in list
- 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
- 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
- Accessing Web Resources using Factory Method Design Pattern in Python
- Setting and accessing name of a Label - PyQt5
- PyQt5 – Setting and accessing name of a Label
- PyQt5 – Setting and accessing description of a Status Bar
- PyQt5 – Setting and accessing name of a Status Bar
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.