Tutorial by Examples

Let's take a sample class. class Book: def __init__(self, title, author): self.title = title self.author = author book1 = Book(title="Right Ho, Jeeves", author="P.G. Wodehouse") In Python you can access the attribute title of the class using the dot ...
For the sake of data encapsulation, sometimes you want to have an attribute which value comes from other attributes or, in general, which value shall be computed at the moment. The standard way to deal with this situation is to create a method, called getter or a setter. class Book: def __init...

Page 1 of 1