Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Inheritance Complex Relationships

Orange().squeeze()

Is this all it would take to change the True/False answer to the question: making the last line return self.has_pulp?

Like so:

class Orange(Fruit):
    has_pulp = True

    def squeeze(self):
        return self.has_pulp

(originally the code in the question is: return has_pulp)

Thank you for your input and any clarity on the conceptual understanding -- it is always appreciated!

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

You are correct.

Even though we have a self.has_pulp set to True, we can access it directly, or through a method like squeeze.

One other thing you can look into is the "@property" decorator which changes it up a little more. Even though there is a method declared pulp_filled. It does not require parenthesis to access from the instantiated object.

Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class Orange:
...    has_pulp = True

...    def squeeze(self):
...       return self.has_pulp

...    @property
...    def pulp_filled(self):
...       return self.has_pulp
...
>>> o = Orange()
>>> o.has_pulp
True
>>> o.squeeze
<bound method Orange.squeeze of <__main__.Orange instance at 0x027ABF30>>
>>> o.squeeze()
True
>>> o.pulp_filled
True
>>>