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: |

Telegram Auto-Delete Messages in Any Chat

Some messages aren’t supposed to last forever. There are some Telegram groups and conversations where it’s best if messages are automatically deleted in a day or a week. Here’s how to auto-delete messages in any Telegram chat. You can enable the auto-delete feature on a per-chat basis. It works for both one-on-one conversations and group chats. Previously, you needed to use the Secret Chat feature to automatically delete messages after a set time. At the time of writing, you can choose to automatically delete messages after a day or a week. Telegram starts the timer once they are sent, not after they are read. This won’t affect the messages that were sent before enabling the feature.

Launched in 2013, Telegram allows users to broadcast messages to a following via “channels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.telegram from pl


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