Answer the question
In order to leave comments, you need to log in
Where does None come from when outputting 2 class instances?
Good day everyone! When outputting 2 objects to the console, None is displayed. There are no errors. None appears immediately after print,
Это похоже на ящик размером 50x30 и весом 2кг
None
В ящике размером 50x30 и весом 2кг оказалось 7 золотых монет
None
class Box:
def __init__(self, size, weight, contains):
self.size = size
self.weight = weight
self.contains = contains
def observe(self):
print(f'Это похоже на ящик размером {self.size} и весом {self.weight}кг')
class Container(Box):
def open(self):
print(f'В ящике размером {self.size} и весом {self.weight}кг оказалось {self.contains}')
box_1 = Box('30x30', 1, '15 золотых монет')
container_1 = Container('50x30', 2, '7 золотых монет')
# Код проверки, не удаляйте его
try:
Box
except:
print("Класс Box не задан")
try:
Container
except:
print("Класс Container не задан")
try:
Container.open
except:
print("Метод open у Container не задан или с ошибкой")
try:
Container.observe
except:
print("Метод observe у Container не наследуется или с ошибкой")
try:
box_1
except:
print("Экземпляр box_1 не существует")
try:
container_1
except:
print("Экземпляр container_1 не существует")
print(container_1.observe())
print(container_1.open())
Answer the question
In order to leave comments, you need to log in
The observe method returns nothing. You are trying to output it as nothing, so you get None.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question