class Node: """Node represents a single node of a linked list""" def __init__(self, val): self.val = val self.next = None def __str__(self): return str(self.val) + " -> " + str(self.next) class LinkedList: def __init__(self): self.head = None self.tail = None def add(self, val): if(not self.head): node = Node(val) self.head = node self.tail = node else: node = Node(val) self.tail.next = node self.tail = node def __str__(self): return str(self.head) def main(): list = LinkedList() list.add(1) list.add(2) list.add(3) print(list) if __name__ == "__main__": main()