Chapter 14: Python Objects Flashcards
A variable that is part of a class.
attribute
A template that can be used to construct an object. Defines the attributes and methods that will make up the object.
Like a cookie cutter that creates cookies (objects)
class
A new class created when a parent class is extended. Inherits all of the attributes and methods of the parent class.
child class
An optional specially named method (__init__) that is called at the moment when a class is being used to construct an object. Usually this is used to set up initial values for the object.
constructor
An optional specially named method (__del__) that is called at the moment just before an object is destroyed. These are rarely used.
destructor
When we create a new class (child) by extending an existing class (parent). The child class has all the attributes and methods of the parent class plus additional attributes and methods defined by the child class.
inheritance
A function that is contained within a class and the objects that are constructed from the class. Some object-oriented patterns use ‘message’ to describe this concept.
method
A constructed instance of a class. Contains all of the attributes and methods that were defined by the class. Some object-oriented documentation uses the term ‘instance’ interchangeably with this.
object
an = PartyAnimal() similar to counts = dict()
(constructs object using dict template, returns instance of dictionary, assigns to counts variable)
The class which is being extended to create a new child class. The parent class contributes all of its methods and attributes to the new child class.
Aka super
parent class
List method to retrieve items from a list
__getitem__
list.__getitem__(index)
list_class.__getitem__(list, index)
called to do any initial setup of the data we want to store in the object
__init__()
def __init__(self):
First class method parameter that gives us access to the object instance so we can set attributes and call methods using dot notation.
self
self.x = 0
keyword defines a template indicating what data and code will be contained in each object of type (name)
class
class PartyAnimal:
indented methods and attributes
Class object lifecycle
Define a class (template), use that class to create an instance of that class (object), and then use the instance. When the program finishes, all of the variables are discarded
special syntax for init method in child class to call init method from parent class
super().__init__(parameter)