Here's a Doctest box:
>>> p = Animal('Pooh') >>> p.name 'Pooh' >>> p.addFriend('Piglet') >>> p.friends ['Piglet']
This should generate a syntax error:
class Animal(): pass
This should compile but not satisfy the doctest:
class Animal: pass
And this should work:
class Animal: def __init__(self, name): self.name = name self.friends = [] def addFriend(self, friend): self.friends.append(friend)