Python is a language that tries to push the object-oriented paradigm to its maximum. This means that its object model is very powerful compared to that of other languages, but also that the behaviour of Python code may result surprising to new programmers.
In this post I want to review the methods that Python provides to access object attributes, trying to provide a comprehensive overview of the matter to everyone wants to start programming in this beautiful language.
What are attributes
Since the nomenclature may vary from language to language, let me name things. In Python we call attribute everything is contained inside an object. In Python there is no real distinction between plain data and functions, being both objects, so what I will say about attributes is perfectly valid even for methods.
As a working example, in this post I will use the following class. It represents a book with a title and an author. It also provides a
get_entry() method which