__len__, and its objects are then used as True or False.
class Queue:
def __init__(self, *items):
self.items = list(items)
def __len__(self):
return len(self.items)
q1, q2 = Queue(), Queue(0)
print(bool(q1), bool(q2), len(q2) and "busy" or "idle")
What does the program print?Log in to join the discussion.
Loading…