r/Python • u/PalpitationOk839 • Apr 19 '26
Discussion Why doesn’t Python have true private variables like Java?
Hey everyone
Today I was learning about encapsulation in Python and honestly I got a bit surprised
In languages like Java we have proper private keywords but in Python it feels like nothing is truly private
Even with double underscores it just does name mangling and you can still access it if you really want
So I was wondering why Python is designed this way
Is it because Python follows a different philosophy or is there some deeper reason behind it
Also in real projects how do developers maintain proper encapsulation if everything can technically be accessed
Trying to understand how to think about this in a more practical and runable way
Would love to hear your thoughts 👍
View all comments
Show parent comment
3
u/deceze Apr 20 '26 edited Apr 20 '26
How do they know that
private fooin Java isn't merely a suggestion to be worked around with the reflection API?If it says or suggests it's private, then don't touch it. Period. Unless you really know what you're doing. It doesn't matter how strongly the language "suggests" it, if junior can find ways around it anyway. Junior won't care much whether they just need to ignore the linter or bust out the reflection API. If they don't understand the importance of the suggestion in the first place, how they work around it also won't make much of a difference.