Concept Flow - Public attributes
Create object
Access public attribute
Read or modify attribute value
Use updated value in program
End
This flow shows how a public attribute of an object is created, accessed, and modified directly.
class Car: def __init__(self, color): self.color = color car = Car('red') print(car.color) car.color = 'blue' print(car.color)
| Step | Action | Attribute 'color' Value | Output |
|---|---|---|---|
| 1 | Create Car object with color='red' | red | |
| 2 | Print car.color | red | red |
| 3 | Change car.color to 'blue' | blue | |
| 4 | Print car.color | blue | blue |
| 5 | End of program | blue |
| Variable | Start | After Step 1 | After Step 3 | Final |
|---|---|---|---|---|
| car.color | undefined | red | blue | blue |
Public attributes in Python classes are variables accessible directly from object instances. They can be read or changed freely using dot notation (object.attribute). No special methods are needed to access or modify them. Example: obj.attr = value or print(obj.attr). They provide simple, direct data storage in objects.