Hippo.health VS hippo.health()

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    health = "good"
    def __init__(self, name, age):
        self.name = name
        self.age = age
    # Add your method here!
    def description(self):
        print self.name
        print self.age
hippo = Animal("Jim",20)
sloth = Animal("Jen",22)
ocelot = Animal("Jill",18)
print hippo.health
print sloth.health
print ocelot.health
print hippo.description()

Actually this code works very well. However, with hippo.health(), the editor shows the following error: TypeError: 'str' object is not callable.

What is a difference between hippo.health and hippo.health()?


health() in this case would be a method of the Animal class

In this case health be either an instance or class varible


Clear enough. thank you


The error - TypeError: 'str' object is not callable - is very clear in itself.

By typing hippo.health, you are accessing the value ("good") of the instance variable (health) of the object hippo.
By appending () to your statement print hippo.health, you get print hippo.health(), which Python interprets to be: print the return value of calling hippo.health. But, the value of hippo.health ("good") is of string type ('str' object), which is not a function/method, and, therefore, it is not callable. Hence, a TypeError is raised.