class Mobile:
def __init__(self,brand,price):
self.brand = brand
self.price = price
mob1=Mobile("Apple", 1000)
mob2=Mobile("Samsung", 5000)
mob3=Mobile("Apple", 3000)
mob_dict = {
"m1":mob1,
"m2":mob2,
"m3":mob3
}
lit = []
for key,value in mob_dict.items():
if value.price > 3000:
lit.append(value)
print (value.brand,value.price)
print(lit)输出:
[<__main__.Mobile object at 0x000001C45C721100>]请解释为什么我会得到这个输出。
发布于 2021-03-29 22:23:24
您正在打印整个对象,您可以执行print(lit[0])或:
for elem in lit:
print(elem)https://stackoverflow.com/questions/66855949
复制相似问题