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

Andras Andras
Andras Andras
7,941 Points

Kenneth = Thief, is not Kenneth = Thief()

Hello,

I have just found that Kenneth = Thief, is not Kenneth = Thief().

<p>
kenneth = Thief
kenneth.sneaky
True
kenneth.sneaky = False
kenneth.sneaky
False
Thief.sneaky
False 
</p>

I expected that Thief.sneaky will be True. It seem we need to use parenthesis.

<p>
kenneth = Thief()
kenneth.sneaky
True
kenneth.sneaky = False
kenneth.sneaky
False
Thief.sneaky
True
</p>
Steven Parker
Steven Parker
230,274 Points

Something odd happened to your formatting .. it seems to have HTML tags mixed in with the python. Did you add them?

Also if you add the letter "py" after the first 3 backticks, you get syntax coloring which can enhance readability.

1 Answer

Steven Parker
Steven Parker
230,274 Points

When you use the parentheses, you are invoking the class constructor and creating a new instance of that class. Any properties that are part of that instance can be changed without affecting the class itself.

But when you make an assignment without the parentheses, you don't get a new instance but just a new word that references the class directly. So the properties using either word are the properties of the class itself.