September 2026
1051 pages
35h 4m
English
In addition to methods, instances can also have attributes. An attribute constitutes a named part of the overall instance value. For example, every complex number has the attributes real and imag for accessing its real or imaginary part:
>>> number = 5 + 6j>>> number.real5.0>>> number.imag6.0
Because an expression of the form reference.attribute is itself a reference, it can be used like any other reference. For example, it can appear as an operand in calculations or be stored in a list:
>>> number.real*number.real + 5*number.imag55.0>>> [1, number.imag, number.real][1, 6.0, 5.0]
In particular, the instance referenced by reference.attribute may itself have an aaa attribute, which can then be accessed by reference.attribute.aaa ...
Read now
Unlock full access