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 (retired) Hack-n-Slash Finishing The Game

Sergei Miroshnikov
Sergei Miroshnikov
3,313 Points

formatting

.format(self.monster) and .format(self.monster()) is there a difference between them ? Code below is from this video .

if player_choice == 'a' : print ("You're attacking {} ! ".format(self.monster))
if self.player.attack(): if self.monster.dodge(): print ("{} dodged the attack!".format(self.monster()))

self.monster you are looking for the name of the monster in the current instance and self.monster() your saying return the monster() method of the current instance which should throw an error if I am correct as there is no monster method.

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Both would be considered attributes of the current instance (that's what the self. means). self.monster(), though, would try to call the monster method belonging to the current instance. self.monster would simply look for an attribute named monster and use it, whether it's a variable or method or whatever. If it's a method, though, this version won't result in the method being called.

Alan Ng
Alan Ng
13,368 Points

yes, I think without parentheses python will not execute monster as a method rather it will treat it as variable. Hope this help.