- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Attribute Accessibility Quiz
We explore how to define a class Person with a twist: making the age attribute private using two underscores. When we attempt to print p.name and p.__age for our instance p, Python throws an error. Why? Because direct access to private attributes (__age) is restricted in Python, ensuring encapsulation and protecting the data.
But don't worry! We introduce a workaround with a method get_age that safely returns the private age. By calling p.name and p.get_age(), we access both public and private attributes smoothly. This lesson is a must for Python coders looking to understand class privacy and object-oriented programming better. Hit like, subscribe for more Python insights, and check out our recommended video to master Python classes! 🛠✨
Видео Attribute Accessibility Quiz канала Michael - Coding Tutor
But don't worry! We introduce a workaround with a method get_age that safely returns the private age. By calling p.name and p.get_age(), we access both public and private attributes smoothly. This lesson is a must for Python coders looking to understand class privacy and object-oriented programming better. Hit like, subscribe for more Python insights, and check out our recommended video to master Python classes! 🛠✨
Видео Attribute Accessibility Quiz канала Michael - Coding Tutor
Комментарии отсутствуют
Информация о видео
24 февраля 2024 г. 21:10:48
00:00:56
Другие видео канала




















