Confused about __str__ on list in Python [duplicate]
This question already has an answer here: Python __str__ and lists 9 answers Coming from a Java background, I understand that __str__ is something like a Python version of toString (while I do realize that Python is the older language). So, I have defined a little class along with an __str__ method as follows: class Node: def __init__(self, id): self.id = id self.neighbours = [] self.distance = 0 def __str__(self): return str(self.id) I then create a few instances of it: uno = Node(1) due = Node(2) tri = Node(3) qua = Node(4) Now, the expected behaviour when trying to print one of these