TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What is encapsulation in Python?

5 pointsby xcodingover 8 years ago

1 comment

bjw181over 8 years ago
What is encapsulation in any language? Put simply, we encapsulate mainly to prevent mistakingly altering data. For example, private methods and variables.<p><pre><code> Class Foo: def __init__(self): self.__im_private() def bar(self): print(&#x27;baz&#x27;) def __im_private(self): print(&#x27;back off, I can only be called by the class&#x27;)</code></pre>
评论 #12880858 未加载