Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Basic Object-Oriented Python Welcome to OOP Adding to our Panda

__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

panda.py
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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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 :smiley:

Hope this helps! :sparkles:

Hi 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?