## Definition A reusable template which is used to create [[objects|objects]]. *Noun.* > The `Person` class is the template used to create individual `Person` objects. ## Characteristics - Used in [[object-oriented programming]]; - defines the [[method|methods]] available to its [[instance|instances]]—one of these is the class [[constructor]]; - defines the [[attribute|attributes]] available to its instances; - multiple instances of the same class can exist; and - can [[inheritance|inherit]] attributes and methods from a parent class. ## Examples ### Class with one attribute and two methods This class has one attribute (`name`) and two methods: its constructor and `introduce()`. ```python class Person: def __init__(self, p_name): self.name = p_name def introduce(self): print(f"My name is {self.name}") ``` This class can be used to create Person objects which will have a `name` attribute and `introduce()` method. ### Class with inheritance This class [[inheritance|inherits]] from the parent class `Person`. ```python class Student(Person): def __init__(self, p_name, p_id): super().__init__(p_name) # invoke the Person constructor self.student_id = p_id ``` This class can be used to create `Student` objects which are a type of `Person`. `Student` objects have `name` and `student_id` attributes and an `introduce()` method. ## Non-examples ### Object [[object|Objects]] are [[instance|instances]] of a class, created using the class as a template. If classes are cookie cutters, objects are cookies. ```python alice = Person("Alice") # a Person object sam = Student("Sam", 2) # a Student object ```