0

I am new to Python. I could not figure out what "is True" means in this case:

class Answers():
    def get_reference(self):
        return None

    def is_private(self):
        return getattr(self, 'private', False) is True

I understand that getattr() will return the value of "private" or it will return False as the default value. So what does the "is True" mean?

cerhovice
  • 676
  • 1
  • 10
  • 24

1 Answers1

2

It's checking whether the getattr call returns True.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 2
    To be more precise, it's checking whether the getattr call returns *exactly* `True`, not some other trueish value. I don't see why you would do that, though. It's usually cleaner to convert trueish values to true and falseish values to false, which you can do with `bool()`. – Kevin Dec 28 '14 at 15:58