Chapter 14: Python Objects Flashcards

1
Q

A variable that is part of a class.

A

attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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)

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A new class created when a parent class is extended. Inherits all of the attributes and methods of the parent class.

A

child class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

An optional specially named method (__del__) that is called at the moment just before an object is destroyed. These are rarely used.

A

destructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A

inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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.

A

method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.

A

object

an = PartyAnimal() similar to counts = dict()
(constructs object using dict template, returns instance of dictionary, assigns to counts variable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

parent class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

List method to retrieve items from a list

A

__getitem__
list.__getitem__(index)
list_class.__getitem__(list, index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

called to do any initial setup of the data we want to store in the object

A

__init__()

def __init__(self):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

First class method parameter that gives us access to the object instance so we can set attributes and call methods using dot notation.

A

self
self.x = 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

keyword defines a template indicating what data and code will be contained in each object of type (name)

A

class

class PartyAnimal:
indented methods and attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Class object lifecycle

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

special syntax for init method in child class to call init method from parent class

A

super().__init__(parameter)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly