Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Question
In python, you have following class definition:
class Test ( object ):
def __init__ ( self ):
self . __a = 'a'

And you define instance of Test as follows:
t = Test()
What is the only way to access 'a', the value of the private variable __a'?
Answer
t._Test__a

Question
In python, you have following class definition:
class Test ( object ):
def __init__ ( self ):
self . __a = 'a'

And you define instance of Test as follows:
t = Test()
What is the only way to access 'a', the value of the private variable __a'?
Answer
?

Question
In python, you have following class definition:
class Test ( object ):
def __init__ ( self ):
self . __a = 'a'

And you define instance of Test as follows:
t = Test()
What is the only way to access 'a', the value of the private variable __a'?
Answer
t._Test__a
If you want to change selection, open document below and click on "Move attachment"

python - What is the meaning of a single- and a double-underscore before an object name? - Stack Overflow
s You can still access .__mangled variables if you desperately want to. The double underscores just namemangles, or renames, the variable to something like instance._className__mangled Example: <span>class Test(object): def __init__(self): self.__a = 'a' self._b = 'b' >>> t = Test() >>> t._b 'b' t._b is accessible because it is only hidden by convention >>> t.__a Traceback (most recent call last): File "<st

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.