2

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!"

4
  • 5
    Assign class boolean value in Python Commented Dec 5, 2013 at 0:56
  • 1
    @gongzhitaao - Wow. You found/posted a duplicate in less than a minute. Talk about being on the ball. Commented Dec 5, 2013 at 0:57
  • 1
    @just luck to find the right google keyword :) Commented Dec 5, 2013 at 0:58
  • 1
    Thanks for that :P I did try to search, but I guess I just chose the wrong words. Commented Dec 5, 2013 at 1:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.