+ 8
Python Strong-Private-Objects
Suppose I have a class, Account, In this class i have, username="XYZ" _balance=12345 __pasw="pass123" We know, the balance and the pasw are hidden objects, so, inorder to get the password (__pasw) outside the class we type, print(_Account__pasw) But as per my requirement, I want to throw an error for accessing a private object. How would I achieve this. The following is my file you may edit it. https://code.sololearn.com/ca20A253A17A/?ref=app Any help is greatly appreciated, Thank You.
2 Réponses
0
You can use @property decorator which ensures your variable is read only. The set method of the @property is only possible if you implement it in your code.
0
Gmuhammed🇳🇬 (CHALLENGE ACCEPTED) Could you elaborate or edit the python file above, please...