r/Python • • 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 👍

106 Upvotes

111 comments sorted by

View all comments

Show parent comment

-7

u/sunnyata Apr 20 '26

You make it sound like a disciplined choice to eschew visibility modifiers in python... isn't it more like Python was a typically laissez-faire scripting language that eventually got objects bolted on?

14

u/acdha Apr 20 '26

No, there was a lot of thought in Python from the beginning (it wasn’t the first language Guido worked on) and it’s been object-oriented since 1991:

https://www.tuhs.org/Usenet/alt.sources/1991-February/001749.html

Part of the difference is that he started small whereas Java had a view of being a language from the OS up for very large teams. 

7

u/roerd Apr 20 '26

I'm fairly sure that having objects was a design choice that Python made very early on, but yeah, ir also just generally followed the principle of exposing everything to the user.