The REPL invokes __repr__
function of your class. So, you can override __str__
and __repr__
functions like this
class uf_node:
def __init__(self, Vertex):
self.vertex = Vertex
self.rep = Vertex
def set_rep(self, Rep):
self.rep = Rep
def __str__(self):
return "Rep: {}, Vertex: {}".format(self.rep, self.vertex)
def __repr__(self):
return "Rep: {}, Vertex: {}".format(self.rep, self.vertex)
With this change,
>>> u = uf_node('a')
>>> u
Rep: a, Vertex: a
>>>
Note: You can read more about the differences between __str__
and __repr__
in this excellent answer