Object Identity and Attributes
Explore Python's object model to understand object identity, attributes, and methods. This lesson helps you learn how to access and modify an object's internal state using the dot operator, and how methods act as callable attributes. You'll also discover how Python supports dynamic attribute assignment on user-defined functions, deepening your understanding of objects in Python.
We'll cover the following...
In Python, everything is an object. An object is not just an abstract entity in memory. It groups together data and the behavior that operates on that data. If a variable is a name that references an object, attributes are the data and methods defined on that object.
In this lesson, we examine the internal structure of objects and learn how to interact with them using the dot (.) operator.
Accessing data with attributes
In Python, an object’s state is represented by its attributes. An attribute is a variable associated with an object. Attributes are accessed using dot notation, such as object.attribute.
Python’s built-in types use attributes to represent their internal data. The complex type provides a simple example. In mathematics, a complex number consists of a real part and an imaginary part. In Python, a complex object exposes these values ...