Class

A class is a code template for creating objects. a common metaphor for classes is architect's drawings.

Python Example

For more Python class related examples, see:

In Python, a class is an object. As an object, you can:

  • assign it to a variable

  • add attributes to it

  • copy it

  • pass it as a function parameter

# Define a class.
class World:
    kind = 'planet'
    def __init__(self, name):
        self.planet = name
        self.motions = []
    def motion(self, motion):
        self.motions.append(motion)
        

# Use the class.
world1 = World('Mars')
world1.motion('spin')
world1.motion('wobble')
print(world1.kind + ' ' + world1.planet + ': ' + str(world1.motions))