Creating a Class with Parameters

A class instance is often created (also called "instantiated") with parameters whose values are determined when the program is run and that the functions in the class needs to know about for whatever the function does.

Python uses the special function name __init__ for constructing a class with parameters.  This function always takes self as the first parameter, because the class constructor needs to know its own instance, just like the class' functions.

Python
class Animal():
    def __init__(self, animal):
        self.animal = animal;

    def speak(self):
        if self.animal == 'Dog':
            print('woof')

        if self.animal == 'Cat':
            print('meow')

animal1 = Animal('Dog')
animal1.speak()

animal2 = Animal('Cat')
animal2.speak()

Output

woof
meow