1

Lets say I am implementing a new type of list.

List types in python evaluate to False if they are not populated. How could I get my class to have this sort of behaviour?

class Example(object):
    def __init__(self, value):
        self.value = value

    def __something__(self):
        return self.value

So then;

if Example(True):
    print "Yay!"

if not Example(False):
    print "Yay!"

The ideal return would be two lines of "Yay!"

Shadow
  • 6,976
  • 4
  • 39
  • 52

0 Answers0