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 Inheritance Quiz

Yu-Che Hung
PLUS
Yu-Che Hung
Courses Plus Student 10,607 Points

why this will return false?

why will this return false?

Stuart Wright
Stuart Wright
41,120 Points

That quiz contains several questions - can you post which question it is you're interested in please?

2 Answers

Steven Parker
Steven Parker
231,236 Points

I'll guess you are asking about the question that shows this code:

class Orange(Fruit):
    has_pulp = True

    def squeeze(self):
        return has_pulp

And then says "Orange().squeeze() will return True."

The issue here is that since the "squeeze" method returns "has_pulp" and not "self.has_pulp" we don't have any information to really know what it will return. It might return True, perhaps there's a global variable (not shown here) that was also set to True. It could just as easily have been set to False. Or perhaps it is not defined and the function will cause a NameError exception.

So since we can't say for sure that it will return True, the statement itself is then false.

Yu-Che Hung
PLUS
Yu-Che Hung
Courses Plus Student 10,607 Points

why they use Orange().squeeze()? Should not we use Orange(instance).squeeze()?

Steven Parker
Steven Parker
231,236 Points

There's no constructor that requires an argument, so "Orange()" by itself should return a new instance.