Section | Video Links |
---|---|
Command Overview | |
Command Use Case | |
Single Leading Underscore |
... Refer to Book or Design Patterns In Python website to read textual content.
... Refer to Book or Design Patterns In Python website to read textual content.
... Refer to Book or Design Patterns In Python website to read textual content.
python ./command/command_concept.py
Executing Command 1
Executing Command 2
Executing Command 1
Executing Command 2
... Refer to Book or Design Patterns In Python website to read textual content.
python ./command/client.py
Light turned ON
Light turned OFF
Light turned ON
Light turned OFF
11:23:35 : ON
11:23:35 : OFF
11:23:35 : ON
11:23:35 : OFF
Light turned ON
Light turned OFF
The single leading underscore _variable
, on your class variables is a useful indicator to other developers that this property should be considered private.
Private, in C style languages, means that the variable/field/property is hidden and cannot be accessed outside of the class. It can only be used internally by its own class methods.
Python does not have a public/private accessor concept so the variable is not actually private and can still be used outside of the class in other modules.
It is just a useful construct that you will see developers use as a recommendation not to reference this variable directly outside of this class, but use a dedicated method or property instead.
... Refer to Book or Design Patterns In Python website to read textual content.