Python is not Java. If you need to set or get the members of a class or object, just expose the member publicly and access it directly. If you need to perform some computations before getting or setting the member, then use Python’s built-in property decorator.

The programmer below comes to Python from a long career as a Java programmer. For every class member that he wants to expose publicly, he defines a get and set method for that member. This is common practice in Java, but is frowned upon in Python as a waste of time and a cause of unnecessary code.

In Python it is acceptable to simply access class or object members directly. The modified code below exposes the length member as a public member. This is signified by the fact that there is no underscore character at the beginning of the member name. The get_length() and set_length() methods are no longer necessary so they have been deleted.