Answer the question
In order to leave comments, you need to log in
What is the meaning of single and double underscore before a variable or method when defining a class?
Good afternoon. I just can't figure out the meaning of the single underscore.
They write that it adds privacy, but I can still refer to all objects:
_internal_name = 'one_nodule' # private variable
_internal_version = '1.0' # private variable
class _Base: # private class
_hidden_factor = 2 # private variable
def __init__(self, price ):
self._price = price
def _double_price(self): # private method
return self._price * self._hidden_factor
def get_double_price(self):
return self._double_price()
Regarding the double, could you clarify. I realized that the _ClassName__method is being decoded, but I don’t quite understand how it looks in practice
Thanks in advance
Answer the question
In order to leave comments, you need to log in
Example An
attempt to call a private method results in an error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question