0

OOP

How would the attribute __a of the class b be accessed from outside the class?

22nd Feb 2019, 4:49 PM
Joanes Lúcio Ferreira
Joanes Lúcio Ferreira - avatar
2 Respuestas
+ 3
Its called pseudo private class variable, with the two underscores prefix. They are not truly private, just a bit obfuscated. This is how you can access them: https://code.sololearn.com/caqn8lQkDFKt/?ref=app
22nd Feb 2019, 8:14 PM
Tibor Santa
Tibor Santa - avatar
+ 3
With instantiating the class: t = b() print(t._b__a) Without instantiating: print(b.__dict__['_b__a'])
22nd Feb 2019, 8:30 PM
Tibor Santa
Tibor Santa - avatar