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

Hanwen Zhang
Hanwen Zhang
15,509 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

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:

Hanwen Zhang
Hanwen Zhang
15,509 Points

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?