May 2019
Beginner
528 pages
29h 51m
English
In programming languages such as C++, Java and C#, classes state explicitly which class members are publicly accessible. Class members that may not be accessed outside a class definition are private and visible only within the class that defines them. Python programmers often use “private” attributes for data or utility methods that are essential to a class’s inner workings but are not part of the class’s public interface.
As you’ve seen, Python objects’ attributes are always accessible. However, Python has a naming convention for “private” attributes. Suppose we want to create an object of class Time and to prevent the following assignment statement:
wake_up._hour = 100
that would set the hour to an invalid ...
Read now
Unlock full access