【发布时间】:2020-09-06 04:14:49
【问题描述】:
get_objects 函数是返回并显示位置的内容,>[main.things object at 0x000002624BB2BDF0>] 这是我第一次做 OOP。 如何显示实际列表。
class room():
def __init__(self, name):
self.__exits = {}
self.__name = name
self.__description = None
self.__objects = []
def add_objects(self, things):
self.__objects.append(things)
def get_objects(self):
return self.__objects
class things(room):
def __init__(self, name, is_weapon):
self.name = name
self.weapon = is_weapon
def weapon(self):
self.is_weapon = True
def not_weapon(self):
self.is_weapon = False
currentRoom = center
alive = True
while alive:
print(currentRoom.get_name())
print(currentRoom.get_desc())
print("Objects here: ",currentRoom.get_objects())
【问题讨论】:
标签: python python-3.x list oop