> For the complete documentation index, see [llms.txt](https://igor-19.gitbook.io/qa/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://igor-19.gitbook.io/qa/avtomatizaciya-testirovaniya/python/oop-v-python-vo-vsekh-podrobnostyakh/privatnost-svoistv.-name-mangling-_name-i-__name.md).

# Приватность свойств. Name Mangling (\_name и \_\_name)

Для установления приватности для класса добавляют `__` в начале имени свойства (переменной, функции)

```python
from datetime import datetime


class Person:
    def __init__(self, name, surname, birthday):
        self._name = name
        self._surname = surname
        self.__birthday = birthday 
        self.name = f"{self._name} {self._surname}"

    @staticmethod
    def _get_current_time():
        return datetime.now()

    def _show_birthday(self):
        return self.__birthday

    def print_data(self):
        print(f"Now {self._get_current_time()}: {self.name} Birthday: {self._show_birthday()}")


people1 = Person("Dmitry", "Budaev", "14.04.1989")
12345678910111213141516171819202122
```

```python
print(people1.print_data)
# дословно - связный метод Person.print_data объекта Person
# <bound method Person.print_data of <__main__.Person object at 0x7fb9ef1a1690>>

print(hex(id(people1)))
# 0x7fb9ef1a1690s

print(people1.__dict__)
# {'_name': 'Dmitry', '_surname': 'Budaev', '_Person__birthday': '14.04.1989', 'name': 'Dmitry Budaev'}

#  '_Person__birthday' - это и есть защищённый метод self.__birthday
```
