Python Programming UNIT 4
Python Programming UNIT 4
Creating a Class:
The Car class is defined with attributes brand and model, and a
method display_info.
Key Concepts:
Creating Methods:
Types of Methods:
Encapsulation:
Benefits:
You can create a date object using the date(year, month, day)
constructor, specifying the year, month, and day as arguments.
Accessing Attributes:
The date object has three attributes: year, month, and day, which
represent the components of the date.
Accessing Attributes Using Functions in Python:
This function returns the value of the attribute named name of the
specified object. If the attribute does not exist, it raises an
AttributeError unless a default value is provided.
2. hasattr(object, name):
This function deletes the attribute named name from the specified
object. If the attribute does not exist, it raises an AttributeError.
Benefits:
2. __doc__:
3. __name__:
This attribute contains the name of the module in which the class is
defined. It provides the module namespace to which the class
belongs.
Note: These built-in class attributes are mainly used for introspection
and reflection purposes, allowing you to examine and manipulate
classes and their attributes dynamically at runtime. They provide
valuable information about the structure and properties of Python
classes, facilitating advanced programming techniques and
debugging tasks.