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 trialMarcus De Silva
1,717 PointsThief vs Thief()
Hello,
I am curious why when assigning a name to the thief e.g. kenneth = Thief() it is done as a method? I tried it with kenneth = Thief, but when I try to call the method pickpocket() I receive a typeError. Could someone clarify that for me?
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsHey Marcus De Silva, good question. Python allows for passing around references to classes and function without executing the code.
The reference Thief
(no parens) refers to the class. This is how class attributes and classmethods
are referenced: Thief.clsmethod
. Calling a class method would be Thief.clsmethod()
.
The reference Thief()
(with parens) refers to βcalling the classβ. This execution creates an instance of the class.
See more in Python docs on classes
Post back if you need more help. Good luck!!!