Telegram Group & Telegram Channel
💭 Что такое интроспекция в Python?

Интроспекция — это способность программы изучать объекты во время выполнения: узнавать их тип, структуру, атрибуты, методы и даже иерархию наследования.

🧩 Это мощный инструмент, встроенный в Python (а также доступный в других языках, например Java, PHP, Ruby). Он позволяет, например:

— Проверить тип объекта с помощью type()
— Проверить, к какому классу принадлежит объект — isinstance(obj, Class)
— Получить список доступных атрибутов и методов — dir(obj)
— Изучить содержимое объекта — через __dict__

Пример:
class Foo:
def __init__(self, val):
self.x = val
def bar(self):
return self.x

obj = Foo(5)
print(dir(obj))


Результат:
['__class__', '__dict__', ..., 'bar', 'x']


Это удобно для отладки, разработки, рефлексии, создания универсальных функций, которые могут работать с разными типами данных.

Библиотека собеса по Python
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/py_interview_lib/805
Create:
Last Update:

💭 Что такое интроспекция в Python?

Интроспекция — это способность программы изучать объекты во время выполнения: узнавать их тип, структуру, атрибуты, методы и даже иерархию наследования.

🧩 Это мощный инструмент, встроенный в Python (а также доступный в других языках, например Java, PHP, Ruby). Он позволяет, например:

— Проверить тип объекта с помощью type()
— Проверить, к какому классу принадлежит объект — isinstance(obj, Class)
— Получить список доступных атрибутов и методов — dir(obj)
— Изучить содержимое объекта — через __dict__

Пример:

class Foo:
def __init__(self, val):
self.x = val
def bar(self):
return self.x

obj = Foo(5)
print(dir(obj))


Результат:
['__class__', '__dict__', ..., 'bar', 'x']


Это удобно для отладки, разработки, рефлексии, создания универсальных функций, которые могут работать с разными типами данных.

Библиотека собеса по Python

BY Библиотека собеса по Python | вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/py_interview_lib/805

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Tata Power whose core business is to generate, transmit and distribute electricity has made no money to investors in the last one decade. That is a big blunder considering it is one of the largest power generation companies in the country. One of the reasons is the company's huge debt levels which stood at ₹43,559 crore at the end of March 2021 compared to the company’s market capitalisation of ₹44,447 crore.

NEWS: Telegram supports Facetime video calls NOW!

Secure video calling is in high demand. As an alternative to Zoom, many people are using end-to-end encrypted apps such as WhatsApp, FaceTime or Signal to speak to friends and family face-to-face since coronavirus lockdowns started to take place across the world. There’s another option—secure communications app Telegram just added video calling to its feature set, available on both iOS and Android. The new feature is also super secure—like Signal and WhatsApp and unlike Zoom (yet), video calls will be end-to-end encrypted.

telegram from nl


Telegram Библиотека собеса по Python | вопросы с собеседований
FROM USA