return 用户定义对象列表中的每个字符串表示换行

return each string representation in a list of user-defined objects in a new line

我有一个列表,其中每个元素都是用户定义的 class、class_object_list。我希望 return 该列表的每个字符串表示在一个新行中,并且代码需要包装在一个 f 字符串中(或者可以在 return 语句中工作)。

或者基本上,将以下代码的等效内容放入 return 语句

for i in class_object_list:
    print(i)

我试过 ''.join([str(i) for i in class_object_list]) 但它不会在新行中打印每个字符串表示形式。

也尝试了 nl = '\n'f"{nl.join([*class_object_list])}",但出现 TypeError: sequence item 0: expected str instance 错误。

并尝试了 print(*class_object_list, sep='\n') 但它只适用于打印语句

使用:

'\n'.join([str(i) for i in class_object_list])

或者:

'\n'.join(map(str, class_object_list))