import random as r
class wow():
def __init__(self):
self.num=r.randint(0,10)
a=[]
for x in range(5):
a.append(wow())
_ = list(map(lambda x: print(x.num, end=' '), a))
# prints:
2 8 0 6 5
您还可以使用while循环并捕获StopIteration
g = iter(a)
while True:
try:
print(next(g).num, end=' ')
except StopIteration:
break
您可以向类中添加
__str__()
方法:然后只需打印:
您将获得:
此外,阅读此Link可能有助于获得更好的线索:
我不建议这样做,但您可以将
map
与lambda函数一起使用您还可以使用while循环并捕获
StopIteration
相关问题 更多 >
编程相关推荐