Introduction to Classes_They're Multiplying!


#1

What is the difference:

description(hippo)

V/S

hippo.description()


#2

the first one is a function call, the second a method call (methods are function inside classes), code:

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    health   = "good"
    def __init__(self, name, age):
        self.name = name
        self.age = age
    # description method of class animal
    def description(self):
        print self.name
        print self.age
hippo = Animal("David", 12)
hippo.description()

# description function
def description():
     print "This is an animal"

description(hippo)

methods can only be called on class instance (hippo in this case)


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.