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

Where did this object come from?

The code below is in one of the Basic object oriented python course quizzes. The question is asking what will be printed in the console. I picked the correct answer (True). However, I am confused on what's happening in the last two lines of code. Especially print(tree.fall()). What is tree doing?
Class Tree: falling_leaves = False def init(self, type): self.type = type

def fall():
    if not falling_leaves:
        falling_leaves = True
    return falling_leaves

tree = Tree(β€˜Cedar’) print(tree.fall())

1 Answer

Hi Cylin George!

tree = Tree('Cedar') is creating an instance of the Tree class using 'Cedar' as the type. The next line is calling the fall method from the newly created tree instance and printing True out to the console.

Hopefully that helps! πŸ––