+ 3

If the class attributes in python are public and can be changed on demand, then how is abstraction achieved in py?

I am learning Oops in py and am confused confused as how will abstraction be achieved if the object's attributes are public and can be easily changed. Also, any class attributes can also be changed. Are the functions private in py?

18th Jul 2022, 3:33 PM
Ruchika Sehgal
Ruchika Sehgal - avatar
4 Respuestas
+ 3
Scope in Python is very weird and it's something I'm still learning and getting used to. I have seen that people implement their own way of making abstract classes (since there's no abstract keyword) by making use of the abc package (which stands for Abstract Base Classes and it native to python) and importing a decorator called abstractmethod.
18th Jul 2022, 4:29 PM
Justice
Justice - avatar
+ 1
There is always a way to manipulate private attributes.it counts for every language. Init is not public as you see . It is a dunder (__init__) Other languages say:you must not access private attributes Python says: you should not
18th Jul 2022, 6:25 PM
Oma Falk
Oma Falk - avatar
0
Justice Thank you for the reply mam, python supports oops weirdly I must say. Just learnt about private attributes that can be used. Any way to make the functions private too?
18th Jul 2022, 5:36 PM
Ruchika Sehgal
Ruchika Sehgal - avatar
0
Oh okay, clearer now. Thanks Oma Falk sir.
20th Jul 2022, 8:13 PM
Ruchika Sehgal
Ruchika Sehgal - avatar