Найти - Пользователи
Полная версия: oop для малышей
Начало » Python для новичков » oop для малышей
1
del3d
Привет Всем!
Имеется класс A и класс B. Создаем объект a1 от класса A.
Как из метода класса A создать объект b1 от класса B? Но только чтобы b1 был не атрибутом a1, а самостоятельным объектом.
Ferroman
>>> class A:
... def create_b(self):
... b = B()
... return b
...
>>> class B:pass
...
>>> a = A()
>>> b = a.create_b()
>>> b
<__main__.B instance at 0x94e822c>
>>>
del3d
Спасибо, большое!
что-то я не допетрил return-ом вернуть..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB