A class can have any number of member variables. These are variables that are available to all members of a class.
hippo = Animal("Jake", 12) cat = Animal("Boots", 3) print hippo.is_alive hippo.is_alive = False print hippo.is_alive print cat.is_alive
- In the example above, we create two instances of an
- Then we print out
True, the default value stored in hippo’s
- Next, we set that to False and print it out to make sure.
- Finally, we print out
True, the value stored in cat’s
is_alivemember variable. We only changed the variable in hippo, not in cat.
Let’s add another member variable to
After line 3, add a second member variable called
health that contains the string
Then, create two new
ocelot. (Give them whatever names and ages you like.)
Finally, on three separate lines,
health of your