【发布时间】:2012-10-17 12:07:10
【问题描述】:
所以我有一个类,叫做Vertex。
class Vertex:
'''
This class is the vertex class. It represents a vertex.
'''
def __init__(self, label):
self.label = label
self.neighbours = []
def __str__(self):
return("Vertex "+str(self.label)+":"+str(self.neighbours))
我想打印一个此类的对象列表,如下所示:
x = [Vertex(1), Vertex(2)]
print x
但它向我显示了这样的输出:
[<__main__.Vertex instance at 0xb76ed84c>, <__main__.Vertex instance at 0xb76ed86c>]
实际上,我想为每个对象打印Vertex.label 的值。
有什么办法吗?
【问题讨论】:
标签: python