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 trialHanwen Zhang
20,084 Points__init__ () argument question
class Panda: species = 'Ailuropoda melanoleuca' food = 'bamboo'
def __init__(self, name, age):
self.is_hungry = True
self.name = name
self.age = age
why we need to take name and age as argument in the init(self, name, age): along with the self, but we don't need to put 'is_hungry' inside the () as well ?
Thanks
class Panda:
species = 'Ailuropoda melanoleuca'
food = 'bamboo'
def __init__(self, name, age):
self.is_hungry = True
self.name = name
self.age = age
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Hanwen Zhang! Pandas (as a group) eat a lot of bamboo every day. In fact, so much so that we can pretty much guarantee that any panda is hungry at the time we put it in the system. This is a way to be able to create a panda, and with no other information than the name and age, set it to is_hungry
by default. That way, it only needs the name and the age to create the panda and we assume that it's hungry until it eats
Hope this helps!
Hanwen Zhang
20,084 PointsHanwen Zhang
20,084 PointsHi Jennifer, Thank you for your reply. So panda is_hungry = True as default, can we change the value to False if the panda is full?