Search⌘ K
AI Features

Who Can Access My Data?

Explore how Python manages data access within objects through conventions such as single and double underscore prefixes. Understand Python's unique approach to encapsulation and its design principles, including how name mangling signals private attributes without strict enforcement. This lesson helps you grasp best practices for protecting object data while leveraging Python’s flexible access model.

Most object-oriented programming languages have a concept of access control. This is related to abstraction. Some attributes and methods on an object are marked private, meaning only that object can access them. Others are marked protected, meaning only that class and any subclasses have access. The rest are public, meaning any other object is allowed to access them.

Access of data in Python

Python doesn’t do this. Python doesn’t really believe in enforcing laws that might someday get in our way. Instead, it provides unenforced guidelines and best practices. Technically, all methods and attributes on a class are publicly available. If we want to suggest that a method should not be used publicly, we can put ...