最佳答案
我有一门课,叫 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的值。
有什么办法吗?