__str__ method, and a program joins its objects into one line.
class Tag:
def __init__(self, name):
self.name = name
def __str__(self):
return "#" + self.name
tags = [Tag("py"), Tag("oop")]
print(" ".join(str(t) for t in tags))
print(" ".join(tags))
What happens when the program runs?Log in to join the discussion.
Loading…